Spaces:
Running
Running
Create predtiction.py to get the Predictions
Browse files- predictions.py +24 -0
predictions.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image, ImageDraw
|
2 |
+
from helper import summarize_predictions_natural_language,render_results_in_image
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load object detection pipeline
|
6 |
+
object_detection_pipe = pipeline("object-detection", model="facebook/detr-resnet-50")
|
7 |
+
|
8 |
+
# Load text-to-speech pipeline
|
9 |
+
tts_pipe = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
|
10 |
+
|
11 |
+
def get_predictions(uploaded_image):
|
12 |
+
pil_image = Image.open(uploaded_image)
|
13 |
+
|
14 |
+
# Perform object detection
|
15 |
+
pipeline_output = object_detection_pipe(pil_image)
|
16 |
+
processed_image = render_results_in_image(pil_image, pipeline_output)
|
17 |
+
|
18 |
+
# Summarize predictions
|
19 |
+
text = summarize_predictions_natural_language(pipeline_output)
|
20 |
+
|
21 |
+
# Generate audio from text
|
22 |
+
narrated_text = tts_pipe(text)
|
23 |
+
|
24 |
+
return processed_image, text, narrated_text["audio"][0]
|