Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,11 @@ import gradio as gr
|
|
| 2 |
from PIL import Image
|
| 3 |
# Use a pipeline as a high-level helper
|
| 4 |
from transformers import pipeline
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
def classify_image(image):
|
| 8 |
result = pipe(image, ["cat", "dog", "car", "person", "building"])
|
| 9 |
return result
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
# Use a pipeline as a high-level helper
|
| 4 |
from transformers import pipeline
|
| 5 |
+
import torch
|
| 6 |
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
|
| 9 |
+
pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-large-patch14",device=0 if device == "cuda" else -1)
|
| 10 |
def classify_image(image):
|
| 11 |
result = pipe(image, ["cat", "dog", "car", "person", "building"])
|
| 12 |
return result
|