Update app.py
Browse files
app.py
CHANGED
|
@@ -115,30 +115,15 @@ agent_with_chat_history = RunnableWithMessageHistory(
|
|
| 115 |
|
| 116 |
username = ""
|
| 117 |
|
| 118 |
-
def
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
elif "Guest" in message.lower():
|
| 123 |
-
username = "Guest"
|
| 124 |
-
return username
|
| 125 |
-
else:
|
| 126 |
-
return "Please ask about username.", None
|
| 127 |
|
| 128 |
# Gradio chat response function
|
| 129 |
|
| 130 |
def respond(message, history: list[dict]):
|
| 131 |
|
| 132 |
-
with gr.Blocks():
|
| 133 |
-
with gr.Row():
|
| 134 |
-
with gr.Column():
|
| 135 |
-
gr.ChatInterface(
|
| 136 |
-
login,
|
| 137 |
-
examples=["Guest", "Lina"],
|
| 138 |
-
additional_outputs=[code],
|
| 139 |
-
type="messages"
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
# Step 1: Embed user message
|
| 143 |
try:
|
| 144 |
vectorized_input = embedding_model.embed_query(message)
|
|
@@ -219,12 +204,38 @@ def respond(message, history: list[dict]):
|
|
| 219 |
|
| 220 |
|
| 221 |
# launch ChatInterface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
demo = gr.ChatInterface(
|
| 223 |
respond,
|
| 224 |
title="YAQIN Chatbot",
|
| 225 |
description="Culturally Sensitive Chatbot for Muslim Women Wanting Mental Healthcare. \n\n What\'s on your mind?",
|
| 226 |
type="messages",
|
| 227 |
)
|
| 228 |
-
|
| 229 |
if __name__ == "__main__":
|
| 230 |
demo.launch()
|
|
|
|
| 115 |
|
| 116 |
username = ""
|
| 117 |
|
| 118 |
+
def set_username(name):
|
| 119 |
+
global username
|
| 120 |
+
username = name
|
| 121 |
+
return gr.update(visible=False), gr.update(visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Gradio chat response function
|
| 124 |
|
| 125 |
def respond(message, history: list[dict]):
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
# Step 1: Embed user message
|
| 128 |
try:
|
| 129 |
vectorized_input = embedding_model.embed_query(message)
|
|
|
|
| 204 |
|
| 205 |
|
| 206 |
# launch ChatInterface
|
| 207 |
+
|
| 208 |
+
with gr.Blocks() as demo:
|
| 209 |
+
# Login interface
|
| 210 |
+
login_box = gr.Column(visible=True)
|
| 211 |
+
with login_box:
|
| 212 |
+
gr.Markdown("### Choose a username to begin:")
|
| 213 |
+
with gr.Row():
|
| 214 |
+
btn_lina = gr.Button("Lina")
|
| 215 |
+
btn_guest = gr.Button("Guest")
|
| 216 |
+
|
| 217 |
+
# Chatbot interface
|
| 218 |
+
chatbot_box = gr.Column(visible=False)
|
| 219 |
+
with chatbot_box:
|
| 220 |
+
chatbot = gr.ChatInterface(
|
| 221 |
+
respond,
|
| 222 |
+
title="YAQIN Chatbot",
|
| 223 |
+
description="Culturally Sensitive Chatbot for Muslim Women Wanting Mental Healthcare. \n\n What\'s on your mind?",
|
| 224 |
+
type="messages",
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
# Button actions
|
| 228 |
+
btn_lina.click(fn=set_username, inputs=[], outputs=[login_box, chatbot_box], kwargs={"name": "Lina"})
|
| 229 |
+
btn_guest.click(fn=set_username, inputs=[], outputs=[login_box, chatbot_box], kwargs={"name": "Guest"})
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
'''
|
| 233 |
demo = gr.ChatInterface(
|
| 234 |
respond,
|
| 235 |
title="YAQIN Chatbot",
|
| 236 |
description="Culturally Sensitive Chatbot for Muslim Women Wanting Mental Healthcare. \n\n What\'s on your mind?",
|
| 237 |
type="messages",
|
| 238 |
)
|
| 239 |
+
'''
|
| 240 |
if __name__ == "__main__":
|
| 241 |
demo.launch()
|