Spaces:
Runtime error
Runtime error
Update handle regeneration
Browse files
app.py
CHANGED
@@ -91,16 +91,6 @@ def get_chat_response(chatbot, task_history):
|
|
91 |
|
92 |
def handle_text_input(history, task_history, text):
|
93 |
"""Handle text input from the user."""
|
94 |
-
# Überprüfen, ob das Eingabefeld leer ist
|
95 |
-
if not text:
|
96 |
-
# Wenn das Eingabefeld leer ist, senden Sie eine vordefinierte Anfrage
|
97 |
-
text = "Describe the image for me..."
|
98 |
-
# Aktualisieren Sie das Chat- und Task-Verlauf mit der vordefinierten Anfrage
|
99 |
-
history = history + [(format_text(text), None)]
|
100 |
-
task_history = task_history + [(text, None)]
|
101 |
-
# Rufen Sie get_chat_response auf, um eine Antwort zu generieren
|
102 |
-
return get_chat_response(history, task_history)
|
103 |
-
|
104 |
task_text = text
|
105 |
if len(text) >= 2 and text[-1] in PUNCTUATION and text[-2] not in PUNCTUATION:
|
106 |
task_text = text[:-1]
|
@@ -123,20 +113,17 @@ def clear_history(task_history):
|
|
123 |
task_history.clear()
|
124 |
return []
|
125 |
|
126 |
-
def handle_regeneration(chatbot, task_history
|
127 |
"""Handle the regeneration of the last response."""
|
128 |
print("Regenerate clicked")
|
129 |
print("Before:", task_history, chatbot)
|
130 |
-
if
|
|
|
131 |
return chatbot
|
132 |
|
133 |
-
# Überprüfen, ob das Eingabefeld leer ist
|
134 |
if not input_field.value:
|
135 |
-
# Wenn das Eingabefeld leer ist, senden Sie eine vordefinierte Anfrage
|
136 |
predefined_query = "Describe this image for me..."
|
137 |
-
# Aktualisieren Sie das Eingabefeld mit der vordefinierten Anfrage
|
138 |
input_field.update(value=predefined_query)
|
139 |
-
# Führen Sie die normale Texteingabebehandlung durch
|
140 |
handle_text_input(chatbot, task_history, predefined_query)
|
141 |
else:
|
142 |
item = task_history[-1]
|
@@ -215,10 +202,8 @@ with gr.Blocks(css=css) as demo:
|
|
215 |
|
216 |
gr.Markdown("### Key Features:\n- **Strong Performance**: Surpasses existing LVLMs on multiple English benchmarks including Zero-shot Captioning and VQA.\n- **Multi-lingual Support**: Supports English, Chinese, and multi-lingual conversation.\n- **High Resolution**: Utilizes 448*448 resolution for fine-grained recognition and understanding.")
|
217 |
submit_btn.click(handle_text_input, [chatbot, task_history, query], [chatbot, task_history]).then(
|
218 |
-
|
219 |
-
)
|
220 |
-
|
221 |
-
|
222 |
|
223 |
submit_btn.click(clear_input, [], [query])
|
224 |
clear_btn.click(clear_history, [task_history], [chatbot], show_progress=True)
|
|
|
91 |
|
92 |
def handle_text_input(history, task_history, text):
|
93 |
"""Handle text input from the user."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
task_text = text
|
95 |
if len(text) >= 2 and text[-1] in PUNCTUATION and text[-2] not in PUNCTUATION:
|
96 |
task_text = text[:-1]
|
|
|
113 |
task_history.clear()
|
114 |
return []
|
115 |
|
116 |
+
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]
|
|
|
202 |
|
203 |
gr.Markdown("### Key Features:\n- **Strong Performance**: Surpasses existing LVLMs on multiple English benchmarks including Zero-shot Captioning and VQA.\n- **Multi-lingual Support**: Supports English, Chinese, and multi-lingual conversation.\n- **High Resolution**: Utilizes 448*448 resolution for fine-grained recognition and understanding.")
|
204 |
submit_btn.click(handle_text_input, [chatbot, task_history, query], [chatbot, task_history]).then(
|
205 |
+
get_chat_response, [chatbot, task_history], [chatbot], show_progress=True
|
206 |
+
)
|
|
|
|
|
207 |
|
208 |
submit_btn.click(clear_input, [], [query])
|
209 |
clear_btn.click(clear_history, [task_history], [chatbot], show_progress=True)
|