sitammeur commited on
Commit
61c2cca
·
verified ·
1 Parent(s): b4c1fdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -56
app.py CHANGED
@@ -1,56 +1,56 @@
1
- # Importing the requirements
2
- import warnings
3
- warnings.filterwarnings("ignore")
4
-
5
- import gradio as gr
6
- from src.paligemma.response import caption_image
7
-
8
-
9
- # Image and input parameters
10
- image = gr.Image(type="pil", label="Image")
11
- max_new_tokens = gr.Slider(
12
- minimum=20,
13
- maximum=160,
14
- value=80,
15
- step=10,
16
- label="Max Tokens",
17
- info="Use larger values for detailed captions",
18
- )
19
- language = gr.Dropdown(
20
- choices=["English", "Spanish", "French"],
21
- value="English",
22
- label="Language",
23
- info="Select the caption language",
24
- )
25
-
26
- # Output for the interface
27
- answer = gr.Textbox(label="Generated Caption", show_label=True, show_copy_button=True)
28
-
29
- # Examples for the interface
30
- examples = [
31
- ["images/cat.jpg", 100, "Spanish", False],
32
- ["images/dog.jpg", 80, "English", True],
33
- ["images/bird.jpg", 160, "French", False],
34
- ]
35
-
36
- # Title, description, and article for the interface
37
- title = "PaliGemma 2 Image Captioning"
38
- description = "Gradio Demo for the PaliGemma 2 Vision Language Understanding and Generation model. This model generates natural language captions based on uploaded images. To use it, upload your image, select the desired parameters (or stick with the default settings), and click 'Submit.' You can also choose one of the examples to load a predefined image. For more information, please refer to the links below."
39
- 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>"
40
-
41
-
42
- # Launch the interface
43
- interface = gr.Interface(
44
- fn=caption_image,
45
- inputs=[image, max_new_tokens, language],
46
- outputs=answer,
47
- examples=examples,
48
- cache_examples=True,
49
- cache_mode="lazy",
50
- title=title,
51
- description=description,
52
- article=article,
53
- theme="Monochrome",
54
- flagging_mode="never",
55
- )
56
- interface.launch(debug=False)
 
1
+ # Importing the requirements
2
+ import warnings
3
+ warnings.filterwarnings("ignore")
4
+
5
+ import gradio as gr
6
+ from src.paligemma.response import caption_image
7
+
8
+
9
+ # Image and input parameters
10
+ image = gr.Image(type="pil", label="Image")
11
+ max_new_tokens = gr.Slider(
12
+ minimum=20,
13
+ maximum=160,
14
+ value=80,
15
+ step=10,
16
+ label="Max Tokens",
17
+ info="Use larger values for detailed captions",
18
+ )
19
+ language = gr.Dropdown(
20
+ choices=["English", "Spanish", "French"],
21
+ value="English",
22
+ label="Language",
23
+ info="Select the caption language",
24
+ )
25
+
26
+ # Output for the interface
27
+ answer = gr.Textbox(label="Generated Caption", show_label=True, show_copy_button=True)
28
+
29
+ # Examples for the interface
30
+ examples = [
31
+ ["images/cat.jpg", 100, "Spanish"],
32
+ ["images/dog.jpg", 80, "English"],
33
+ ["images/bird.jpg", 160, "French"],
34
+ ]
35
+
36
+ # Title, description, and article for the interface
37
+ title = "PaliGemma 2 Image Captioning"
38
+ description = "Gradio Demo for the PaliGemma 2 Vision Language Understanding and Generation model. This model generates natural language captions based on uploaded images. To use it, upload your image, select the desired parameters (or stick with the default settings), and click 'Submit.' You can also choose one of the examples to load a predefined image. For more information, please refer to the links below."
39
+ 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>"
40
+
41
+
42
+ # Launch the interface
43
+ interface = gr.Interface(
44
+ fn=caption_image,
45
+ inputs=[image, max_new_tokens, language],
46
+ outputs=answer,
47
+ examples=examples,
48
+ cache_examples=True,
49
+ cache_mode="lazy",
50
+ title=title,
51
+ description=description,
52
+ article=article,
53
+ theme="Monochrome",
54
+ flagging_mode="never",
55
+ )
56
+ interface.launch(debug=False)