merve HF staff commited on
Commit
c7149fd
1 Parent(s): 9c15d06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -94
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
- with gr.Row():
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
-
90
- with gr.Column():
91
-
92
  output = gr.Textbox(label="Output")
93
-
94
- with gr.Accordion():
95
- # Hyper-parameters for generation
96
- max_new_tokens = gr.Slider(
97
- minimum=8,
98
- maximum=1024,
99
- value=512,
100
- step=1,
101
- interactive=True,
102
- label="Maximum number of new tokens to generate",
103
- )
104
- repetition_penalty = gr.Slider(
105
- minimum=0.01,
106
- maximum=5.0,
107
- value=1.2,
108
- step=0.01,
109
- interactive=True,
110
- label="Repetition penalty",
111
- info="1.0 is equivalent to no penalty",
112
- )
113
- temperature = gr.Slider(
114
- minimum=0.0,
115
- maximum=5.0,
116
- value=0.4,
117
- step=0.1,
118
- interactive=True,
119
- label="Sampling temperature",
120
- info="Higher values will produce more diverse outputs.",
121
- )
122
- top_p = gr.Slider(
123
- minimum=0.01,
124
- maximum=0.99,
125
- value=0.8,
126
- step=0.01,
127
- interactive=True,
128
- label="Top P",
129
- info="Higher values is equivalent to sampling more low-probability tokens.",
130
- )
131
- decoding_strategy = gr.Radio(
132
- [
133
- "Greedy",
134
- "Top P Sampling",
135
- ],
136
- value="Greedy",
137
- label="Decoding strategy",
138
- interactive=True,
139
- info="Higher values is equivalent to sampling more low-probability tokens.",
140
- )
141
- decoding_strategy.change(
142
- fn=lambda selection: gr.Slider(
143
- visible=(
144
- selection in ["contrastive_sampling", "beam_sampling", "Top P Sampling", "sampling_top_k"]
145
- )
146
- ),
147
- inputs=decoding_strategy,
148
- outputs=temperature,
149
- )
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=repetition_penalty,
159
- )
160
- decoding_strategy.change(
161
- fn=lambda selection: gr.Slider(visible=(selection in ["Top P Sampling"])),
162
- inputs=decoding_strategy,
163
- outputs=top_p,
164
- )
165
- examples=[["./example_images/docvqa_example.png", "How many items are sold?", "Greedy", 0.4, 512, 1.2, 0.8],
166
- ["./example_images/s2w_example.png", "What is this UI about?", "Greedy", 0.4, 512, 1.2, 0.8],
167
- ["./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],
168
- ["./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],
169
- ["./example_images/baklava.png", "Where is this pastry from?", 0.4, 512, 1.2, 0.8],
170
- ["./example_images/dummy_pdf.png", "How much percent is the order status?", 0.4, 512, 1.2, 0.8],
171
- ["./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]]
172
- gr.Examples(
173
- examples = examples,
174
- inputs=[image_input, query_input, decoding_strategy, temperature,
175
- max_new_tokens, repetition_penalty, top_p],
176
- outputs=output,
177
- fn=model_inference
178
- )
179
- submit_btn.click(model_inference, inputs = [image_input, query_input, decoding_strategy, temperature,
180
- max_new_tokens, repetition_penalty, top_p],
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)