mca183 commited on
Commit
89884e9
·
1 Parent(s): edbe02d

add blip feature and correct torch install

Browse files
Files changed (2) hide show
  1. app.py +19 -4
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,7 +1,22 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import BlipProcessor, BlipForConditionalGeneration
3
 
4
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
5
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
6
 
7
+ def get_completion(raw_image):
8
+
9
+ inputs = processor(raw_image, return_tensors="pt")
10
+ out = model.generate(**inputs)
11
+
12
+ return processor.decode(out[0], skip_special_tokens=True)
13
+
14
+ demo = gr.Interface(fn=get_completion,
15
+ inputs=[gr.Image(label="Upload image", type="pil")],
16
+ outputs=[gr.Textbox(label="Caption")],
17
+ title="Image Captioning with BLIP",
18
+ description="Caption any image using the BLIP model",
19
+ allow_flagging="never",
20
+ examples=["https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg", "https://free-images.com/sm/9596/dog_animal_greyhound_983023.jpg"])
21
+
22
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- transformer[pytorch]
2
  gradio
 
1
+ transformer[torch]
2
  gradio