Alidr79 commited on
Commit
80fdd4f
·
verified ·
1 Parent(s): 633e3ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ from transformers import BlipForConditionalGeneration
4
+
5
+ model = BlipForConditionalGeneration.from_pretrained(
6
+ "Salesforce/blip-image-captioning-base")
7
+ model.to("cuda")
8
+
9
+ processor = AutoProcessor.from_pretrained(
10
+ "Salesforce/blip-image-captioning-base")
11
+
12
+
13
+ @spaces.GPU
14
+ def image_caption(input):
15
+ inputs = processor(input, return_tensors="pt")
16
+ out = model.generate(**inputs)
17
+ return processor.decode(out[0], skip_special_tokens = True)
18
+
19
+
20
+ iface = gr.Interface(fn = image_caption,
21
+ inputs = gr.Image(type='pil'),
22
+ outputs = "text")
23
+
24
+ iface.launch()