Spaces:
Sleeping
Sleeping
app.py
CHANGED
@@ -1,17 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load pipeline
|
5 |
captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
6 |
|
7 |
-
# Define Gradio interface function
|
8 |
def generate_caption(image):
|
9 |
result = captioner(image)
|
10 |
return result[0]["generated_text"].strip()
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
description = "Upload an image and get a descriptive caption using the `nlpconnect/vit-gpt2-image-captioning` model by Hugging Face Transformers."
|
15 |
|
16 |
demo = gr.Interface(
|
17 |
fn=generate_caption,
|
@@ -22,6 +19,5 @@ demo = gr.Interface(
|
|
22 |
allow_flagging="never"
|
23 |
)
|
24 |
|
25 |
-
# Launch the app
|
26 |
if __name__ == "__main__":
|
27 |
demo.launch(share=False)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
|
|
4 |
captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
5 |
|
|
|
6 |
def generate_caption(image):
|
7 |
result = captioner(image)
|
8 |
return result[0]["generated_text"].strip()
|
9 |
|
10 |
+
title = "🖼️ Image Caption Generator"
|
11 |
+
description = "Upload an image and get a caption"
|
|
|
12 |
|
13 |
demo = gr.Interface(
|
14 |
fn=generate_caption,
|
|
|
19 |
allow_flagging="never"
|
20 |
)
|
21 |
|
|
|
22 |
if __name__ == "__main__":
|
23 |
demo.launch(share=False)
|