Siri23 commited on
Commit
5df154e
·
verified ·
1 Parent(s): 47e39bd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+ from PIL import Image
4
+
5
+ # Load the image captioning pipeline
6
+ pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
7
+
8
+ def generate_caption(image):
9
+ # Generate a caption for the image
10
+ captions = pipe(image)
11
+ return captions[0]['generated_text']
12
+
13
+ # Create a Gradio interface for image captioning
14
+ demo = gr.Interface(
15
+ fn=generate_caption,
16
+ inputs=gr.Image(type="pil", label="Upload an Image"),
17
+ outputs=gr.Textbox(label="Generated Caption"),
18
+ title="Image Caption Generator",
19
+ description="Upload an image to generate a caption using the BLIP model."
20
+ )
21
+
22
+ # Launch the Gradio interface
23
+ if __name__ == "__main__":
24
+ demo.launch(share=True)