keithhon commited on
Commit
267974d
·
1 Parent(s): 872e9cc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import requests
4
+ from transformers import CLIPProcessor, CLIPModel
5
+
6
+ model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
7
+ processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
8
+
9
+ def image_feature(uri):
10
+ image = Image.open(requests.get(url, stream=True).raw)
11
+ inputs = processor(images=image, return_tensors="pt")
12
+ image_features = model.get_image_features(**inputs)
13
+ return image_features.numpy().tolist()[0]
14
+
15
+ iface = gr.Interface(fn=image_feature, inputs="text", outputs="text")
16
+ iface.launch()