chethu commited on
Commit
3dd2829
·
verified ·
1 Parent(s): 4e57b06

app.py is updated

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,16 +1,28 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- pipe = pipeline("image-to-text",
5
- model="Salesforce/blip-image-captioning-base")
6
 
 
 
 
 
7
 
8
- def launch(input):
9
- out = pipe(input)
10
- return out[0]['generated_text']
11
 
12
- iface = gr.Interface(launch,
13
- inputs=gr.Image(type='pil'),
14
- outputs="text")
 
 
 
 
 
 
 
 
15
 
16
- iface.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the image-to-text pipeline
5
+ image_to_text_pipeline = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
6
 
7
+ def generate_caption(input_image):
8
+ # Generate caption for the input image
9
+ caption = image_to_text_pipeline(input_image)[0]['generated_text']
10
+ return caption
11
 
12
+ # Additional configuration for the output component
13
+ output_textbox = gr.outputs.Textbox(label="Generated Caption", type="auto", lines=5)
 
14
 
15
+ # Interface for launching the model
16
+ interface = gr.Interface(
17
+ fn=generate_caption,
18
+ inputs=gr.inputs.Image(type='pil', label="Input Image"),
19
+ outputs=output_textbox,
20
+ title="Image Captioning Model",
21
+ description="This model generates captions for images.",
22
+ theme="default",
23
+ layout="vertical",
24
+ allow_screenshot=True
25
+ )
26
 
27
+ # Launch the interface
28
+ interface.launch()