Image_Whisper / predictions.py
chethu's picture
Create predtiction.py to get the Predictions
18edfa9 verified
raw
history blame
839 Bytes
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]