Spaces:
Runtime error
Runtime error
Steven Anderson
commited on
Commit
•
eaa9560
1
Parent(s):
e94e516
Fix
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import clip
|
|
4 |
from PIL import Image
|
5 |
|
6 |
|
7 |
-
def process(device, image, prompt):
|
8 |
print("Inferring...")
|
9 |
image = preprocess(image).unsqueeze(0).to(device)
|
10 |
print(image)
|
@@ -21,19 +21,18 @@ def process(device, image, prompt):
|
|
21 |
return dict(zip(prompts, probs[0]))
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
iface.launch()
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
|
7 |
+
def process(model, preprocess, device, image, prompt):
|
8 |
print("Inferring...")
|
9 |
image = preprocess(image).unsqueeze(0).to(device)
|
10 |
print(image)
|
|
|
21 |
return dict(zip(prompts, probs[0]))
|
22 |
|
23 |
|
24 |
+
print("Getting device...")
|
25 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
26 |
+
print("Loading model...")
|
27 |
+
model, preprocess = clip.load("ViT-B/32", device=device)
|
28 |
+
print("Loaded model.")
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=lambda i, p: process(model, preprocess, device, i, p),
|
32 |
+
inputs=[
|
33 |
+
gr.Image(),
|
34 |
+
gr.Textbox(lines=5, label="Prompts (newline-separated)"),
|
35 |
+
],
|
36 |
+
outputs="label",
|
37 |
+
)
|
38 |
+
iface.launch()
|
|