Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,14 @@ import clip
|
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
from PIL import Image
|
6 |
-
import os
|
7 |
import base64
|
8 |
from io import BytesIO
|
9 |
|
10 |
# Load the CLIP model
|
11 |
model, preprocess = clip.load("ViT-B/32")
|
12 |
-
device = "cuda" if torch.cuda.
|
13 |
model.to(device).eval()
|
14 |
|
15 |
-
# Define the Business Listing variable
|
16 |
-
Business_Listing = "Air Guide"
|
17 |
-
|
18 |
def find_similarity(image_base64, text_input):
|
19 |
# Decode the base64 image string to bytes
|
20 |
image_bytes = base64.b64decode(image_base64)
|
@@ -38,10 +34,12 @@ def find_similarity(image_base64, text_input):
|
|
38 |
|
39 |
return similarity[0, 0]
|
40 |
|
41 |
-
# Define a Gradio interface
|
42 |
iface = gr.Interface(
|
43 |
fn=find_similarity,
|
44 |
-
inputs=[
|
|
|
|
|
|
|
45 |
outputs="number",
|
46 |
live=True,
|
47 |
interpretation="default",
|
|
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
from PIL import Image
|
|
|
6 |
import base64
|
7 |
from io import BytesIO
|
8 |
|
9 |
# Load the CLIP model
|
10 |
model, preprocess = clip.load("ViT-B/32")
|
11 |
+
device = "cuda" if torch.cuda.is available() else "cpu"
|
12 |
model.to(device).eval()
|
13 |
|
|
|
|
|
|
|
14 |
def find_similarity(image_base64, text_input):
|
15 |
# Decode the base64 image string to bytes
|
16 |
image_bytes = base64.b64decode(image_base64)
|
|
|
34 |
|
35 |
return similarity[0, 0]
|
36 |
|
|
|
37 |
iface = gr.Interface(
|
38 |
fn=find_similarity,
|
39 |
+
inputs=[
|
40 |
+
gr.inputs.Textbox(lines=3, label="Enter Base64 Image"),
|
41 |
+
gr.inputs.Textbox(lines=3, label="Enter Text"),
|
42 |
+
],
|
43 |
outputs="number",
|
44 |
live=True,
|
45 |
interpretation="default",
|