Mayada's picture
Create app.py
8ceebf6 verified
raw
history blame
804 Bytes
import gradio as gr
from transformers import pipeline
# Load your image captioning model from Hugging Face
model_name = "Mayada/AIC-transformer" # Update this with your model path
captioner = pipeline("image-to-text", model=model_name)
# Define a function to generate a caption from an image
def generate_caption(image):
result = captioner(image)
return result[0]['generated_text']
# Create a Gradio interface
interface = gr.Interface(
fn=generate_caption, # Function to process image and return caption
inputs=gr.inputs.Image(type="pil"), # Accept image input
outputs="text", # Output the caption as text
title="AIC-transformer-2023", # Title for your interface
description="Description", # Description for users
)
# Launch the Gradio interface
interface.launch()