# Install and update the necessary libraries import logging import sys from PIL import Image from transformers import pipeline import os import gradio as gr # Suppress non-critical log messages from transformers.utils import logging logging.set_verbosity_error() #from helper import ignore_warnings #ignore_warnings() import sys sys.path.append("./Object-Detection/helper.py") # Adjust the path as necessary to point to the directory where helper.py is located from Object-Detection.helper import ignore_warnings ignore_warnings() # Import the pipeline function from the transformers library #from transformers import pipeline # Set up the object detection pipeline. pipe = pipeline("object-detection", model="facebook/detr-resnet-50") #sys.path.append("./Open_Source_Models_with_Hugging_Face/Object_Detection/helper.py") # Adjust the path as necessary to point to the directory where helper.py is located from Object-Detection.helper import import load_image_from_url, render_results_in_image # Load the image from a file #raw_image = Image.open('./Open_Source_Models_with_Hugging_Face/Object_Detection/kittens.jpeg') # Resize the image #raw_image.resize((569, 491)) #pipeline_output = pipe(raw_image) #processed_image = render_results_in_image(raw_image, pipeline_output) #processed_image # gradio interface def get_pipeline_prediction(pil_image): pipeline_output = pipe(pil_image) processed_image = render_results_in_image(pil_image, pipeline_output) return processed_image iface = gr.Interface( fn=get_pipeline_prediction, inputs=gr.Image(label="Input image", type="pil"), outputs=gr.Image(label="Output image with predicted instances", type="pil") ) iface.launch()