Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -188,7 +188,29 @@ print(top_results)
|
|
| 188 |
#Defining chatbot giving user a UI to interact, see their conversation history, and see new messages using built in gr feature
|
| 189 |
#ChatInterface requires at least one parameter(a function)
|
| 190 |
chatbot = gr.ChatInterface(respond,type="messages", title="Accessible Intelligence Hub", theme="Taithrah/Minimal")
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
with gr.Blocks(
|
| 193 |
theme=gr.themes.Soft(
|
| 194 |
primary_hue="purple",
|
|
@@ -247,27 +269,6 @@ with gr.Blocks(
|
|
| 247 |
#}
|
| 248 |
#"""
|
| 249 |
|
| 250 |
-
def save_chat_history(history, username):
|
| 251 |
-
if not username:
|
| 252 |
-
username = "anonymous"
|
| 253 |
-
|
| 254 |
-
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
| 255 |
-
filename = f"chat_history_{username}_{timestamp}.txt"
|
| 256 |
-
|
| 257 |
-
with open(filename, "w", encoding="utf-8") as f:
|
| 258 |
-
f.write(f"Chat History for {username} - {timestamp}\n\n")
|
| 259 |
-
for exchange in history:
|
| 260 |
-
if isinstance(exchange, tuple) and len(exchange) == 2:
|
| 261 |
-
user_msg, bot_msg = exchange
|
| 262 |
-
f.write(f"User: {user_msg}\n")
|
| 263 |
-
f.write(f"Bot: {bot_msg}\n\n")
|
| 264 |
-
elif isinstance(exchange, dict):
|
| 265 |
-
# Handle dictionary format if needed
|
| 266 |
-
role = exchange.get("role", "unknown")
|
| 267 |
-
content = exchange.get("content", "")
|
| 268 |
-
f.write(f"{role.capitalize()}: {content}\n\n")
|
| 269 |
-
|
| 270 |
-
return filename
|
| 271 |
|
| 272 |
#with gr.Blocks() as demo:
|
| 273 |
chatbot = gr.Chatbot()
|
|
|
|
| 188 |
#Defining chatbot giving user a UI to interact, see their conversation history, and see new messages using built in gr feature
|
| 189 |
#ChatInterface requires at least one parameter(a function)
|
| 190 |
chatbot = gr.ChatInterface(respond,type="messages", title="Accessible Intelligence Hub", theme="Taithrah/Minimal")
|
| 191 |
+
|
| 192 |
+
def save_chat_history(history, username):
|
| 193 |
+
if not username:
|
| 194 |
+
username = "anonymous"
|
| 195 |
+
|
| 196 |
+
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
| 197 |
+
filename = f"chat_history_{username}_{timestamp}.txt"
|
| 198 |
+
|
| 199 |
+
with open(filename, "w", encoding="utf-8") as f:
|
| 200 |
+
f.write(f"Chat History for {username} - {timestamp}\n\n")
|
| 201 |
+
for exchange in history:
|
| 202 |
+
if isinstance(exchange, tuple) and len(exchange) == 2:
|
| 203 |
+
user_msg, bot_msg = exchange
|
| 204 |
+
f.write(f"User: {user_msg}\n")
|
| 205 |
+
f.write(f"Bot: {bot_msg}\n\n")
|
| 206 |
+
elif isinstance(exchange, dict):
|
| 207 |
+
# Handle dictionary format if needed
|
| 208 |
+
role = exchange.get("role", "unknown")
|
| 209 |
+
content = exchange.get("content", "")
|
| 210 |
+
f.write(f"{role.capitalize()}: {content}\n\n")
|
| 211 |
+
|
| 212 |
+
return filename
|
| 213 |
+
|
| 214 |
with gr.Blocks(
|
| 215 |
theme=gr.themes.Soft(
|
| 216 |
primary_hue="purple",
|
|
|
|
| 269 |
#}
|
| 270 |
#"""
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
#with gr.Blocks() as demo:
|
| 274 |
chatbot = gr.Chatbot()
|