carolcarneiro commited on
Commit
69b2598
·
verified ·
1 Parent(s): d7d0fc0

app.py carol

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+ import base64
4
+ import io
5
+
6
+ # calling pipeline to get_completion
7
+ get_completion = pipeline("image-to-text",model="carolcarneiro/keras-dummy-sequential-demo") #"sashakunitsyn/vlrm-blip2-opt-2.7b") #"Salesforce/blip2-opt-6.7b") # "Salesforce/blip-image-captioning-large" "nlpconnect/vit-gpt2-image-captioning"
8
+
9
+ def summarize(input):
10
+ output = get_completion(input)
11
+ return output[0]['generated_text']
12
+
13
+ def image_to_base64_str(pil_image):
14
+ byte_arr = io.BytesIO()
15
+ pil_image.save(byte_arr, format='PNG')
16
+ byte_arr = byte_arr.getvalue()
17
+ return str(base64.b64encode(byte_arr).decode('utf-8'))
18
+
19
+ def captioner(image):
20
+ #base64_image = image_to_base64_str(image)
21
+ result = get_completion(image)
22
+ return result[0]['generated_text']
23
+
24
+ gr.close_all()
25
+ demo = gr.Interface(fn=captioner,
26
+ inputs=[gr.Image(label="Upload image", type="pil")],
27
+ outputs=[gr.Textbox(label="Caption")],
28
+ title="Image Captioning Application",
29
+ description="Caption the image you'd like to upload",
30
+ allow_flagging="never")
31
+
32
+ demo.launch()