Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load your image captioning model from Hugging Face
|
5 |
+
model_name = "Mayada/AIC-transformer" # Update this with your model path
|
6 |
+
captioner = pipeline("image-to-text", model=model_name)
|
7 |
+
|
8 |
+
# Define a function to generate a caption from an image
|
9 |
+
def generate_caption(image):
|
10 |
+
result = captioner(image)
|
11 |
+
return result[0]['generated_text']
|
12 |
+
|
13 |
+
# Create a Gradio interface
|
14 |
+
interface = gr.Interface(
|
15 |
+
fn=generate_caption, # Function to process image and return caption
|
16 |
+
inputs=gr.inputs.Image(type="pil"), # Accept image input
|
17 |
+
outputs="text", # Output the caption as text
|
18 |
+
title="AIC-transformer-2023", # Title for your interface
|
19 |
+
description="Description", # Description for users
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the Gradio interface
|
23 |
+
interface.launch()
|
24 |
+
|