File size: 950 Bytes
9c53e9f
72afe1e
 
 
9c53e9f
72afe1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from transformers import CLIPProcessor, CLIPModel
from PIL import Image
import requests

# Load the model and processor
model = CLIPModel.from_pretrained("geolocal/StreetCLIP")
processor = CLIPProcessor.from_pretrained("geolocal/StreetCLIP")

def classify_image(image):
    # Preprocess the image
    inputs = processor(images=image, return_tensors="pt")
    # Perform the inference
    outputs = model(**inputs)
    # Postprocess the outputs
    logits_per_image = outputs.logits_per_image  # this is the image-text similarity score
    probs = logits_per_image.softmax(dim=1)  # we can use softmax to get probabilities
    return probs

# Define Gradio interface
iface = gr.Interface(
    fn=classify_image,
    inputs=gr.inputs.Image(type="pil"),
    outputs="text",
    title="Geolocal StreetCLIP Classification",
    description="Upload an image to classify using Geolocal StreetCLIP"
)

# Launch the interface
iface.launch()