he99codes commited on
Commit
48b4d02
·
verified ·
1 Parent(s): 90757af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -1,13 +1,14 @@
 
 
1
  import gradio as gr
2
- from transformers import pipeline
3
- pipe = pipeline(
4
- "image-text-to-text",
5
- model="Salesforce/blip-image-captioning-base"
6
- )
7
- def launch(input):
8
- out = pipe(input)
9
- return out[0]['generated_text']
10
- iface = gr.Interface(launch,
11
- inputs=gr.Image(type='pil'),
12
- outputs="text")
13
- iface.launch()
 
1
+ from transformers import BlipProcessor, BlipForConditionalGeneration
2
+ import torch
3
  import gradio as gr
4
+
5
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
6
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
7
+
8
+ def caption(img):
9
+ inputs = processor(img, return_tensors="pt")
10
+ out = model.generate(**inputs)
11
+ return processor.decode(out[0], skip_special_tokens=True)
12
+
13
+ demo = gr.Interface(caption, gr.Image(type="pil"), "text")
14
+ demo.launch()