Spaces:
Runtime error
Runtime error
Update handle regeneration
Browse files
app.py
CHANGED
@@ -117,69 +117,22 @@ def handle_regeneration(chatbot, task_history):
|
|
117 |
"""Handle the regeneration of the last response."""
|
118 |
print("Regenerate clicked")
|
119 |
print("Before:", task_history, chatbot)
|
120 |
-
|
121 |
-
if not input_field or not isinstance(input_field, tuple) or len(input_field) != 2:
|
122 |
return chatbot
|
123 |
-
|
124 |
-
if
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
128 |
else:
|
129 |
-
|
130 |
-
|
131 |
-
return chatbot
|
132 |
-
task_history[-1] = (item[0], None)
|
133 |
-
chatbot_item = chatbot.pop(-1)
|
134 |
-
if chatbot_item[0] is None:
|
135 |
-
chatbot[-1] = (chatbot[-1][0], None)
|
136 |
-
else:
|
137 |
-
chatbot.append((chatbot_item[0], None))
|
138 |
-
print("After:", task_history, chatbot)
|
139 |
-
|
140 |
return get_chat_response(chatbot, task_history)
|
141 |
|
142 |
-
# Custom CSS
|
143 |
-
css = '''
|
144 |
-
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css');
|
145 |
-
|
146 |
-
.gradio-button, .gradio-upload-button {
|
147 |
-
border: none;
|
148 |
-
border-radius: 4px;
|
149 |
-
cursor: pointer;
|
150 |
-
font-size: 16px;
|
151 |
-
margin: 2px;
|
152 |
-
}
|
153 |
-
|
154 |
-
.gradio-button {
|
155 |
-
background-color: #008CBA;
|
156 |
-
color: white;
|
157 |
-
}
|
158 |
-
|
159 |
-
.gradio-button:hover {
|
160 |
-
background-color: #005f5f;
|
161 |
-
}
|
162 |
-
|
163 |
-
.gradio-upload-button input {
|
164 |
-
display: none;
|
165 |
-
}
|
166 |
-
|
167 |
-
.gradio-upload-button {
|
168 |
-
background-color: #008CBA;
|
169 |
-
color: white;
|
170 |
-
padding: 10px 20px;
|
171 |
-
}
|
172 |
-
|
173 |
-
.gradio-upload-button:hover {
|
174 |
-
background-color: #005f5f;
|
175 |
-
}
|
176 |
-
|
177 |
-
.control-width {
|
178 |
-
width: 100%;
|
179 |
-
}
|
180 |
-
'''
|
181 |
|
182 |
-
with gr.Blocks(
|
183 |
gr.Markdown("# Qwen-VL Multimodal-Vision-Insight")
|
184 |
gr.Markdown(
|
185 |
"## Developed by Keyvan Hardani (Keyvven on [Twitter](https://twitter.com/Keyvven))\n"
|
@@ -207,7 +160,7 @@ with gr.Blocks(css=css) as demo:
|
|
207 |
|
208 |
submit_btn.click(clear_input, [], [query])
|
209 |
clear_btn.click(clear_history, [task_history], [chatbot], show_progress=True)
|
210 |
-
regen_btn.click(handle_regeneration, [chatbot, task_history
|
211 |
upload_btn.upload(handle_file_upload, [chatbot, task_history, upload_btn], [chatbot, task_history], show_progress=True)
|
212 |
|
213 |
|
|
|
117 |
"""Handle the regeneration of the last response."""
|
118 |
print("Regenerate clicked")
|
119 |
print("Before:", task_history, chatbot)
|
120 |
+
if not task_history:
|
|
|
121 |
return chatbot
|
122 |
+
item = task_history[-1]
|
123 |
+
if item[1] is None:
|
124 |
+
return chatbot
|
125 |
+
task_history[-1] = (item[0], None)
|
126 |
+
chatbot_item = chatbot.pop(-1)
|
127 |
+
if chatbot_item[0] is None:
|
128 |
+
chatbot[-1] = (chatbot[-1][0], None)
|
129 |
else:
|
130 |
+
chatbot.append((chatbot_item[0], None))
|
131 |
+
print("After:", task_history, chatbot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
return get_chat_response(chatbot, task_history)
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
with gr.Blocks(theme='gradio/soft') as demo:
|
136 |
gr.Markdown("# Qwen-VL Multimodal-Vision-Insight")
|
137 |
gr.Markdown(
|
138 |
"## Developed by Keyvan Hardani (Keyvven on [Twitter](https://twitter.com/Keyvven))\n"
|
|
|
160 |
|
161 |
submit_btn.click(clear_input, [], [query])
|
162 |
clear_btn.click(clear_history, [task_history], [chatbot], show_progress=True)
|
163 |
+
regen_btn.click(handle_regeneration, [chatbot, task_history], [chatbot], show_progress=True)
|
164 |
upload_btn.upload(handle_file_upload, [chatbot, task_history, upload_btn], [chatbot, task_history], show_progress=True)
|
165 |
|
166 |
|