Daemontatox
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -144,10 +144,10 @@ def create_rag_chain(chat_history: str):
|
|
144 |
chat_history = ChatHistory()
|
145 |
|
146 |
# Gradio Function
|
147 |
-
def ask_question_gradio(question, history
|
148 |
try:
|
149 |
# Add user question to chat history
|
150 |
-
chat_history.add_message("
|
151 |
|
152 |
# Get formatted history
|
153 |
formatted_history = chat_history.get_formatted_history()
|
@@ -161,19 +161,20 @@ def ask_question_gradio(question, history: gr.Chatbot) -> Tuple[str, gr.Chatbot]
|
|
161 |
response += chunk
|
162 |
|
163 |
# Add assistant response to chat history
|
164 |
-
chat_history.add_message("
|
165 |
|
166 |
# Update Gradio chat history
|
167 |
-
history.append(
|
|
|
168 |
|
169 |
return "", history
|
170 |
except Exception as e:
|
171 |
logger.error(f"Error during question processing: {e}")
|
172 |
-
return "", history + [
|
173 |
|
174 |
def clear_chat():
|
175 |
chat_history.clear()
|
176 |
-
return
|
177 |
|
178 |
# Gradio Interface
|
179 |
with gr.Blocks() as iface:
|
@@ -183,6 +184,7 @@ with gr.Blocks() as iface:
|
|
183 |
chatbot = gr.Chatbot(
|
184 |
height=400,
|
185 |
show_label=False,
|
|
|
186 |
)
|
187 |
|
188 |
with gr.Row():
|
@@ -200,9 +202,8 @@ with gr.Blocks() as iface:
|
|
200 |
)
|
201 |
|
202 |
clear_button.click(
|
203 |
-
|
204 |
-
outputs=[chatbot, question_input]
|
205 |
-
_js="() => { window.location.reload(); }"
|
206 |
)
|
207 |
|
208 |
# Launch the Gradio App
|
|
|
144 |
chat_history = ChatHistory()
|
145 |
|
146 |
# Gradio Function
|
147 |
+
def ask_question_gradio(question, history):
|
148 |
try:
|
149 |
# Add user question to chat history
|
150 |
+
chat_history.add_message("user", question)
|
151 |
|
152 |
# Get formatted history
|
153 |
formatted_history = chat_history.get_formatted_history()
|
|
|
161 |
response += chunk
|
162 |
|
163 |
# Add assistant response to chat history
|
164 |
+
chat_history.add_message("assistant", response)
|
165 |
|
166 |
# Update Gradio chat history
|
167 |
+
history.append({"role": "user", "content": question})
|
168 |
+
history.append({"role": "assistant", "content": response})
|
169 |
|
170 |
return "", history
|
171 |
except Exception as e:
|
172 |
logger.error(f"Error during question processing: {e}")
|
173 |
+
return "", history + [{"role": "assistant", "content": "An error occurred. Please try again later."}]
|
174 |
|
175 |
def clear_chat():
|
176 |
chat_history.clear()
|
177 |
+
return [], ""
|
178 |
|
179 |
# Gradio Interface
|
180 |
with gr.Blocks() as iface:
|
|
|
184 |
chatbot = gr.Chatbot(
|
185 |
height=400,
|
186 |
show_label=False,
|
187 |
+
type="messages" # Using the new messages format
|
188 |
)
|
189 |
|
190 |
with gr.Row():
|
|
|
202 |
)
|
203 |
|
204 |
clear_button.click(
|
205 |
+
clear_chat,
|
206 |
+
outputs=[chatbot, question_input]
|
|
|
207 |
)
|
208 |
|
209 |
# Launch the Gradio App
|