Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -81,104 +81,100 @@ with gr.Blocks(fill_height=True) as demo:
|
|
81 |
gr.Markdown("**Important note**: This model is not made for chatting, the chatty IDEFICS2 will be released in the upcoming days. **This model is very strong on various tasks, including visual question answering, document retrieval and more.**")
|
82 |
gr.Markdown("Learn more about IDEFICS2 in this [blog post](https://huggingface.co/blog/idefics2).")
|
83 |
|
84 |
-
|
85 |
-
|
86 |
image_input = gr.Image(label="Upload your Image", type="pil")
|
87 |
query_input = gr.Textbox(label="Prompt")
|
88 |
submit_btn = gr.Button("Submit")
|
89 |
-
|
90 |
-
with gr.Column():
|
91 |
-
|
92 |
output = gr.Textbox(label="Output")
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
"
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
outputs=output)
|
182 |
|
183 |
|
184 |
demo.launch(debug=True)
|
|
|
81 |
gr.Markdown("**Important note**: This model is not made for chatting, the chatty IDEFICS2 will be released in the upcoming days. **This model is very strong on various tasks, including visual question answering, document retrieval and more.**")
|
82 |
gr.Markdown("Learn more about IDEFICS2 in this [blog post](https://huggingface.co/blog/idefics2).")
|
83 |
|
84 |
+
|
85 |
+
with gr.Column():
|
86 |
image_input = gr.Image(label="Upload your Image", type="pil")
|
87 |
query_input = gr.Textbox(label="Prompt")
|
88 |
submit_btn = gr.Button("Submit")
|
|
|
|
|
|
|
89 |
output = gr.Textbox(label="Output")
|
90 |
+
examples=[["./example_images/docvqa_example.png", "How many items are sold?", "Greedy", 0.4, 512, 1.2, 0.8],
|
91 |
+
["./example_images/s2w_example.png", "What is this UI about?", "Greedy", 0.4, 512, 1.2, 0.8],
|
92 |
+
["./example_images/example_images_travel_tips.jpg", "I want to go somewhere similar to the one in the photo. Give me destinations and travel tips.", 0.4, 512, 1.2, 0.8],
|
93 |
+
["./example_images/chicken_on_money.png", "Can you tell me a very short story based on this image?", 0.4, 512, 1.2, 0.8],
|
94 |
+
["./example_images/baklava.png", "Where is this pastry from?", 0.4, 512, 1.2, 0.8],
|
95 |
+
["./example_images/dummy_pdf.png", "How much percent is the order status?", 0.4, 512, 1.2, 0.8],
|
96 |
+
["./example_images/art_critic.png", "As an art critic AI assistant, could you describe this painting in details and make a thorough critic?.", 0.4, 512, 1.2, 0.8]]
|
97 |
+
gr.Examples(
|
98 |
+
examples = examples,
|
99 |
+
inputs=[image_input, query_input, decoding_strategy, temperature,
|
100 |
+
max_new_tokens, repetition_penalty, top_p],
|
101 |
+
outputs=output,
|
102 |
+
fn=model_inference
|
103 |
+
)
|
104 |
+
with gr.Accordion():
|
105 |
+
# Hyper-parameters for generation
|
106 |
+
max_new_tokens = gr.Slider(
|
107 |
+
minimum=8,
|
108 |
+
maximum=1024,
|
109 |
+
value=512,
|
110 |
+
step=1,
|
111 |
+
interactive=True,
|
112 |
+
label="Maximum number of new tokens to generate",
|
113 |
+
)
|
114 |
+
repetition_penalty = gr.Slider(
|
115 |
+
minimum=0.01,
|
116 |
+
maximum=5.0,
|
117 |
+
value=1.2,
|
118 |
+
step=0.01,
|
119 |
+
interactive=True,
|
120 |
+
label="Repetition penalty",
|
121 |
+
info="1.0 is equivalent to no penalty",
|
122 |
+
)
|
123 |
+
temperature = gr.Slider(
|
124 |
+
minimum=0.0,
|
125 |
+
maximum=5.0,
|
126 |
+
value=0.4,
|
127 |
+
step=0.1,
|
128 |
+
interactive=True,
|
129 |
+
label="Sampling temperature",
|
130 |
+
info="Higher values will produce more diverse outputs.",
|
131 |
+
)
|
132 |
+
top_p = gr.Slider(
|
133 |
+
minimum=0.01,
|
134 |
+
maximum=0.99,
|
135 |
+
value=0.8,
|
136 |
+
step=0.01,
|
137 |
+
interactive=True,
|
138 |
+
label="Top P",
|
139 |
+
info="Higher values is equivalent to sampling more low-probability tokens.",
|
140 |
+
)
|
141 |
+
decoding_strategy = gr.Radio(
|
142 |
+
[
|
143 |
+
"Greedy",
|
144 |
+
"Top P Sampling",
|
145 |
+
],
|
146 |
+
value="Greedy",
|
147 |
+
label="Decoding strategy",
|
148 |
+
interactive=True,
|
149 |
+
info="Higher values is equivalent to sampling more low-probability tokens.",
|
150 |
+
)
|
151 |
+
decoding_strategy.change(
|
152 |
+
fn=lambda selection: gr.Slider(
|
153 |
+
visible=(
|
154 |
+
selection in ["contrastive_sampling", "beam_sampling", "Top P Sampling", "sampling_top_k"]
|
155 |
+
)
|
156 |
+
),
|
157 |
+
inputs=decoding_strategy,
|
158 |
+
outputs=temperature,
|
159 |
+
)
|
160 |
+
|
161 |
+
decoding_strategy.change(
|
162 |
+
fn=lambda selection: gr.Slider(
|
163 |
+
visible=(
|
164 |
+
selection in ["contrastive_sampling", "beam_sampling", "Top P Sampling", "sampling_top_k"]
|
165 |
+
)
|
166 |
+
),
|
167 |
+
inputs=decoding_strategy,
|
168 |
+
outputs=repetition_penalty,
|
169 |
+
)
|
170 |
+
decoding_strategy.change(
|
171 |
+
fn=lambda selection: gr.Slider(visible=(selection in ["Top P Sampling"])),
|
172 |
+
inputs=decoding_strategy,
|
173 |
+
outputs=top_p,
|
174 |
+
)
|
175 |
+
|
176 |
+
submit_btn.click(model_inference, inputs = [image_input, query_input, decoding_strategy, temperature,
|
177 |
+
max_new_tokens, repetition_penalty, top_p], outputs=output)
|
|
|
178 |
|
179 |
|
180 |
demo.launch(debug=True)
|