sraimund commited on
Commit
2a95d4c
·
verified ·
1 Parent(s): 0da4252

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -1,7 +1,23 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ import open_clip
5
 
6
+ def greet(image):
7
+ image = Image.fromarray(file_path)
8
+ device = torch.device("cpu")
9
+ model, _, preprocess = open_clip.create_model_and_transforms('ViT-L-14', pretrained='openai', device=device)
10
 
11
+ image = preprocess().unsqueeze(0).to(device)
12
+
13
+ with torch.amp.autocast(device_type=device.type):
14
+ with torch.no_grad():
15
+ image_features = model.encode_image(image)
16
+ image_features /= image_features.norm(dim=-1, keepdim=True)
17
+
18
+ embedding = image_features[0]
19
+
20
+ return str(embedding)
21
+
22
+ demo = gr.Interface(fn=greet, inputs=gr.inputs.Image(), outputs="text")
23
  demo.launch()