pooadi commited on
Commit
0f2351b
·
1 Parent(s): ed1514f

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +23 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load pre-trained image captioning model
5
+ captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
6
+
7
+ # Define function to get caption
8
+ def get_image_caption(image):
9
+ if image is None:
10
+ return "Please upload an image."
11
+ caption = captioner(image)[0]['generated_text']
12
+ return caption
13
+
14
+ # Build Gradio app
15
+ with gr.Blocks() as image_captioning_app:
16
+ gr.Markdown("## 🖼️ Image Captioning App")
17
+ with gr.Row():
18
+ image_input = gr.Image(type="pil", label="Upload an Image")
19
+ caption_output = gr.Textbox(label="Image Caption")
20
+ generate_button = gr.Button("Generate Caption")
21
+ generate_button.click(fn=get_image_caption, inputs=image_input, outputs=caption_output)
22
+
23
+ image_captioning_app.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio