Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,12 +80,6 @@ def generate_response(user_message):
|
|
| 80 |
# -----------------------------
|
| 81 |
# 5️⃣ Chat + Save
|
| 82 |
# -----------------------------
|
| 83 |
-
chat_history = []
|
| 84 |
-
|
| 85 |
-
def chat(user_message):
|
| 86 |
-
bot_response = generate_response(user_message)
|
| 87 |
-
chat_history.append((user_message, bot_response))
|
| 88 |
-
return chat_history, "" # also clears input box
|
| 89 |
|
| 90 |
def save_conversation():
|
| 91 |
if not chat_history:
|
|
@@ -97,7 +91,7 @@ def save_conversation():
|
|
| 97 |
conversation.append({"role": "assistant", "content": str(bot_msg)})
|
| 98 |
|
| 99 |
timestamp = time.strftime("%Y%m%d-%H%M%S")
|
| 100 |
-
file_path = f"conversation_{timestamp}.txt"
|
| 101 |
|
| 102 |
with open(file_path, "w", encoding="utf-8") as f:
|
| 103 |
json.dump(conversation, f, indent=4, ensure_ascii=False)
|
|
@@ -105,61 +99,24 @@ def save_conversation():
|
|
| 105 |
return file_path
|
| 106 |
|
| 107 |
# -----------------------------
|
| 108 |
-
#
|
| 109 |
# -----------------------------
|
|
|
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
gr.Markdown("# Nigerian PIDGIN Assistant")
|
| 112 |
gr.Markdown("Chat with a Nigerian assistant that only speaks Pidgin English.")
|
| 113 |
|
| 114 |
-
chatbot = gr.
|
| 115 |
user_input = gr.Textbox(label="Your message", placeholder="Type your message here...")
|
| 116 |
|
| 117 |
with gr.Row():
|
| 118 |
send_button = gr.Button("Send")
|
| 119 |
save_button = gr.Button("Save Conversation")
|
| 120 |
-
download_file = gr.File(label="Download Conversation")
|
| 121 |
|
| 122 |
-
send_button.click(
|
| 123 |
-
save_button.click(save_conversation, outputs=
|
| 124 |
|
| 125 |
demo.launch()
|
| 126 |
-
|
| 127 |
-
# def save_conversation():
|
| 128 |
-
# if not chat_history:
|
| 129 |
-
# return None
|
| 130 |
-
|
| 131 |
-
# conversation = []
|
| 132 |
-
# for user_msg, bot_msg in chat_history:
|
| 133 |
-
# conversation.append({"role": "user", "content": str(user_msg)})
|
| 134 |
-
# conversation.append({"role": "assistant", "content": str(bot_msg)})
|
| 135 |
-
|
| 136 |
-
# timestamp = time.strftime("%Y%m%d-%H%M%S")
|
| 137 |
-
# file_path = f"conversation_{timestamp}.json"
|
| 138 |
-
|
| 139 |
-
# with open(file_path, "w", encoding="utf-8") as f:
|
| 140 |
-
# json.dump(conversation, f, indent=4, ensure_ascii=False)
|
| 141 |
-
|
| 142 |
-
# return file_path
|
| 143 |
-
|
| 144 |
-
# # -----------------------------
|
| 145 |
-
# # 5️⃣ Gradio interface
|
| 146 |
-
# # -----------------------------
|
| 147 |
-
|
| 148 |
-
# with gr.Blocks() as demo:
|
| 149 |
-
# gr.Markdown("# Nigerian PIDGIN Assistant")
|
| 150 |
-
# gr.Markdown("Chat with a Nigerian assistant that only speaks Pidgin English.")
|
| 151 |
-
|
| 152 |
-
# chatbot = gr.Textbox(label="Conversation", lines=15, interactive=False)
|
| 153 |
-
# user_input = gr.Textbox(label="Your message", placeholder="Type your message here...")
|
| 154 |
-
|
| 155 |
-
# with gr.Row():
|
| 156 |
-
# send_button = gr.Button("Send")
|
| 157 |
-
# save_button = gr.Button("Save Conversation")
|
| 158 |
-
|
| 159 |
-
# send_button.click(generate_response, inputs=user_input, outputs=chatbot)
|
| 160 |
-
# save_button.click(save_conversation, outputs=gr.File())
|
| 161 |
-
|
| 162 |
-
# demo.launch()
|
| 163 |
# iface = gr.Interface(
|
| 164 |
# fn=generate_response,
|
| 165 |
# inputs=gr.Textbox(lines=2, placeholder="Enter your message..."),
|
|
|
|
| 80 |
# -----------------------------
|
| 81 |
# 5️⃣ Chat + Save
|
| 82 |
# -----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
def save_conversation():
|
| 85 |
if not chat_history:
|
|
|
|
| 91 |
conversation.append({"role": "assistant", "content": str(bot_msg)})
|
| 92 |
|
| 93 |
timestamp = time.strftime("%Y%m%d-%H%M%S")
|
| 94 |
+
file_path = f"conversation_{timestamp}.txt"
|
| 95 |
|
| 96 |
with open(file_path, "w", encoding="utf-8") as f:
|
| 97 |
json.dump(conversation, f, indent=4, ensure_ascii=False)
|
|
|
|
| 99 |
return file_path
|
| 100 |
|
| 101 |
# -----------------------------
|
| 102 |
+
# 5️⃣ Gradio interface
|
| 103 |
# -----------------------------
|
| 104 |
+
|
| 105 |
with gr.Blocks() as demo:
|
| 106 |
gr.Markdown("# Nigerian PIDGIN Assistant")
|
| 107 |
gr.Markdown("Chat with a Nigerian assistant that only speaks Pidgin English.")
|
| 108 |
|
| 109 |
+
chatbot = gr.Textbox(label="Conversation", lines=15, interactive=False)
|
| 110 |
user_input = gr.Textbox(label="Your message", placeholder="Type your message here...")
|
| 111 |
|
| 112 |
with gr.Row():
|
| 113 |
send_button = gr.Button("Send")
|
| 114 |
save_button = gr.Button("Save Conversation")
|
|
|
|
| 115 |
|
| 116 |
+
send_button.click(generate_response, inputs=user_input, outputs=chatbot)
|
| 117 |
+
save_button.click(save_conversation, outputs=gr.File())
|
| 118 |
|
| 119 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
# iface = gr.Interface(
|
| 121 |
# fn=generate_response,
|
| 122 |
# inputs=gr.Textbox(lines=2, placeholder="Enter your message..."),
|