Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,62 @@
|
|
1 |
-
# Installing the latest version of the transformers library
|
2 |
-
import os
|
3 |
-
os.system("pip install ./transformers-4.47.0.dev0-py3-none-any.whl")
|
4 |
-
|
5 |
-
# Importing the requirements
|
6 |
-
import warnings
|
7 |
-
warnings.filterwarnings("ignore")
|
8 |
-
|
9 |
-
import gradio as gr
|
10 |
-
from src.app.response import describe_image
|
11 |
-
|
12 |
-
|
13 |
-
# Image, text query, and input parameters
|
14 |
-
image = gr.Image(type="pil", label="Image")
|
15 |
-
text = gr.Textbox(label="Question", placeholder="Enter your question here")
|
16 |
-
max_new_tokens = gr.Slider(
|
17 |
-
minimum=20, maximum=160, step=
|
18 |
-
)
|
19 |
-
|
20 |
-
# Output for the interface
|
21 |
-
answer = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
|
22 |
-
|
23 |
-
# Examples for the interface
|
24 |
-
examples = [
|
25 |
-
[
|
26 |
-
"images/cat.jpg",
|
27 |
-
"How many cats are there?",
|
28 |
-
80,
|
29 |
-
],
|
30 |
-
[
|
31 |
-
"images/dog.jpg",
|
32 |
-
"What color is the dog?",
|
33 |
-
80,
|
34 |
-
],
|
35 |
-
[
|
36 |
-
"images/bird.jpg",
|
37 |
-
"What is the bird doing?",
|
38 |
-
160,
|
39 |
-
],
|
40 |
-
]
|
41 |
-
|
42 |
-
# Title, description, and article for the interface
|
43 |
-
title = "Visual Question Answering"
|
44 |
-
description = "Gradio Demo for the PaliGemma 2 Vision Language Understanding and Generation model. This model can answer questions about images in natural language. To use it, upload your image, type a question, select associated parameters, use the default values, click 'Submit', or click one of the examples to load them. You can read more at the links below."
|
45 |
-
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2412.03555' target='_blank'>Model Paper</a> | <a href='https://huggingface.co/google/paligemma2-3b-ft-docci-448' target='_blank'>Model Page</a></p>"
|
46 |
-
|
47 |
-
|
48 |
-
# Launch the interface
|
49 |
-
interface = gr.Interface(
|
50 |
-
fn=describe_image,
|
51 |
-
inputs=[image, text, max_new_tokens],
|
52 |
-
outputs=answer,
|
53 |
-
examples=examples,
|
54 |
-
cache_examples=True,
|
55 |
-
cache_mode="lazy",
|
56 |
-
title=title,
|
57 |
-
description=description,
|
58 |
-
article=article,
|
59 |
-
theme="Nymbo/Nymbo_Theme",
|
60 |
-
flagging_mode="never",
|
61 |
-
)
|
62 |
-
interface.launch(debug=False)
|
|
|
1 |
+
# Installing the latest version of the transformers library
|
2 |
+
import os
|
3 |
+
os.system("pip install ./transformers-4.47.0.dev0-py3-none-any.whl")
|
4 |
+
|
5 |
+
# Importing the requirements
|
6 |
+
import warnings
|
7 |
+
warnings.filterwarnings("ignore")
|
8 |
+
|
9 |
+
import gradio as gr
|
10 |
+
from src.app.response import describe_image
|
11 |
+
|
12 |
+
|
13 |
+
# Image, text query, and input parameters
|
14 |
+
image = gr.Image(type="pil", label="Image")
|
15 |
+
text = gr.Textbox(label="Question", placeholder="Enter your question here")
|
16 |
+
max_new_tokens = gr.Slider(
|
17 |
+
minimum=20, maximum=160, step=10, value=80, label="Max Tokens"
|
18 |
+
)
|
19 |
+
|
20 |
+
# Output for the interface
|
21 |
+
answer = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
|
22 |
+
|
23 |
+
# Examples for the interface
|
24 |
+
examples = [
|
25 |
+
[
|
26 |
+
"images/cat.jpg",
|
27 |
+
"How many cats are there?",
|
28 |
+
80,
|
29 |
+
],
|
30 |
+
[
|
31 |
+
"images/dog.jpg",
|
32 |
+
"What color is the dog?",
|
33 |
+
80,
|
34 |
+
],
|
35 |
+
[
|
36 |
+
"images/bird.jpg",
|
37 |
+
"What is the bird doing?",
|
38 |
+
160,
|
39 |
+
],
|
40 |
+
]
|
41 |
+
|
42 |
+
# Title, description, and article for the interface
|
43 |
+
title = "Visual Question Answering"
|
44 |
+
description = "Gradio Demo for the PaliGemma 2 Vision Language Understanding and Generation model. This model can answer questions about images in natural language. To use it, upload your image, type a question, select associated parameters, use the default values, click 'Submit', or click one of the examples to load them. You can read more at the links below."
|
45 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2412.03555' target='_blank'>Model Paper</a> | <a href='https://huggingface.co/google/paligemma2-3b-ft-docci-448' target='_blank'>Model Page</a></p>"
|
46 |
+
|
47 |
+
|
48 |
+
# Launch the interface
|
49 |
+
interface = gr.Interface(
|
50 |
+
fn=describe_image,
|
51 |
+
inputs=[image, text, max_new_tokens],
|
52 |
+
outputs=answer,
|
53 |
+
examples=examples,
|
54 |
+
cache_examples=True,
|
55 |
+
cache_mode="lazy",
|
56 |
+
title=title,
|
57 |
+
description=description,
|
58 |
+
article=article,
|
59 |
+
theme="Nymbo/Nymbo_Theme",
|
60 |
+
flagging_mode="never",
|
61 |
+
)
|
62 |
+
interface.launch(debug=False)
|