File size: 804 Bytes
8ceebf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()