scr930 commited on
Commit
72afe1e
·
verified ·
1 Parent(s): 9c53e9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -1,3 +1,30 @@
1
  import gradio as gr
 
 
 
2
 
3
- gr.load("models/geolocal/StreetCLIP").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import CLIPProcessor, CLIPModel
3
+ from PIL import Image
4
+ import requests
5
 
6
+ # Load the model and processor
7
+ model = CLIPModel.from_pretrained("geolocal/StreetCLIP")
8
+ processor = CLIPProcessor.from_pretrained("geolocal/StreetCLIP")
9
+
10
+ def classify_image(image):
11
+ # Preprocess the image
12
+ inputs = processor(images=image, return_tensors="pt")
13
+ # Perform the inference
14
+ outputs = model(**inputs)
15
+ # Postprocess the outputs
16
+ logits_per_image = outputs.logits_per_image # this is the image-text similarity score
17
+ probs = logits_per_image.softmax(dim=1) # we can use softmax to get probabilities
18
+ return probs
19
+
20
+ # Define Gradio interface
21
+ iface = gr.Interface(
22
+ fn=classify_image,
23
+ inputs=gr.inputs.Image(type="pil"),
24
+ outputs="text",
25
+ title="Geolocal StreetCLIP Classification",
26
+ description="Upload an image to classify using Geolocal StreetCLIP"
27
+ )
28
+
29
+ # Launch the interface
30
+ iface.launch()