Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|