GermanySutherland commited on
Commit
b522f96
·
verified ·
1 Parent(s): 919124d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Pretrained vision-to-text model
5
+ captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
6
+
7
+ def generate_caption(image):
8
+ result = captioner(image)[0]['generated_text']
9
+ return result
10
+
11
+ # Gradio UI
12
+ demo = gr.Interface(
13
+ fn=generate_caption,
14
+ inputs=gr.Image(type="filepath"),
15
+ outputs=gr.Textbox(label="Generated Caption"),
16
+ title="Mini Image Captioner",
17
+ description="Upload an image and get a natural language caption (Vision + LLM)"
18
+ )
19
+
20
+ if __name__ == "__main__":
21
+ demo.launch()