Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,14 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import gradio as gr
|
| 4 |
|
|
@@ -7,7 +17,7 @@ detection_model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-5
|
|
| 7 |
detection_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
| 8 |
description_generator = pipeline("text-generation", model="gpt-2")
|
| 9 |
|
| 10 |
-
# Function to recognize and describe product
|
| 11 |
def recognize_and_describe(image):
|
| 12 |
inputs = detection_processor(images=image, return_tensors="pt")
|
| 13 |
outputs = detection_model(**inputs)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from subprocess import check_call
|
| 4 |
+
|
| 5 |
+
# Ensure transformers is installed
|
| 6 |
+
try:
|
| 7 |
+
from transformers import DetrImageProcessor, DetrForObjectDetection, pipeline
|
| 8 |
+
except ImportError:
|
| 9 |
+
check_call([sys.executable, "-m", "pip", "install", "transformers==4.33.2"])
|
| 10 |
+
from transformers import DetrImageProcessor, DetrForObjectDetection, pipeline
|
| 11 |
+
|
| 12 |
from PIL import Image
|
| 13 |
import gradio as gr
|
| 14 |
|
|
|
|
| 17 |
detection_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
| 18 |
description_generator = pipeline("text-generation", model="gpt-2")
|
| 19 |
|
| 20 |
+
# Function to recognize and describe a product
|
| 21 |
def recognize_and_describe(image):
|
| 22 |
inputs = detection_processor(images=image, return_tensors="pt")
|
| 23 |
outputs = detection_model(**inputs)
|