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