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