Harzis commited on
Commit
aa70c4b
1 Parent(s): d1686ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Image Captioning from:
2
+ # https://learn.deeplearning.ai/courses/open-source-models-hugging-face/lesson/12/image-captioning
3
+ #
4
+
5
+ from transformers import BlipForConditionalGeneration
6
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
7
+
8
+ from transformers import AutoProcessor
9
+ processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
10
+
11
+ from PIL import Image
12
+ import gradio as gr
13
+
14
+ def captioning(input):
15
+ image_tensors = processor(input, return_tensors="pt")
16
+ image_text_tensors = model.generate(**image_tensors)
17
+ output = processor.decode(image_text_tensors[0], skip_special_tokens=True)
18
+ return output
19
+
20
+ gr.close_all()
21
+
22
+ app = gr.Interface(fn=captioning,
23
+ inputs=[gr.Image(label="Laita tähä joku kuva", type="pil")],
24
+ outputs=[gr.Textbox(label="Mitä näkyy?")],
25
+ title="Harzan kuvan selitys aplikaatio",
26
+ description="Harzan ihme aplikaatio kertomaan mitä kuvassa on",
27
+ allow_flagging="never")
28
+ app.launch()
29
+ gr.close_all()