Keyven commited on
Commit
2d256fb
β€’
1 Parent(s): c35d25e

Update handle regeneration

Browse files
Files changed (1) hide show
  1. app.py +12 -59
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
- input_field = chatbot[-1] if chatbot else None
121
- if not input_field or not isinstance(input_field, tuple) or len(input_field) != 2:
122
  return chatbot
123
-
124
- if not input_field.value:
125
- predefined_query = "Describe this image for me..."
126
- input_field.update(value=predefined_query)
127
- handle_text_input(chatbot, task_history, predefined_query)
 
 
128
  else:
129
- item = task_history[-1]
130
- if item[1] is None:
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(css=css) as demo:
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, query], [chatbot], show_progress=True)
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