clean up interface
Browse files
app.py
CHANGED
|
@@ -45,8 +45,11 @@ class SessionChatBot:
|
|
| 45 |
|
| 46 |
def respond(self, message, history):
|
| 47 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 48 |
-
for
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
messages.append({"role": "user", "content": message})
|
| 51 |
|
| 52 |
response = ""
|
|
@@ -60,7 +63,7 @@ class SessionChatBot:
|
|
| 60 |
token = chunk.choices[0].delta.content
|
| 61 |
if token:
|
| 62 |
response += token
|
| 63 |
-
yield
|
| 64 |
|
| 65 |
# Save log after full response
|
| 66 |
self.append_to_session_log(message, response)
|
|
@@ -102,21 +105,14 @@ def create_chatbot():
|
|
| 102 |
|
| 103 |
# ---- Build Gradio Interface ----
|
| 104 |
with gr.Blocks() as demo:
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
title="BoundrAI",
|
| 109 |
-
type="messages", # Switch to OpenAI-style message format
|
| 110 |
-
textbox=gr.Textbox(placeholder="Ask me anything...", container=True),
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
report_btn = gr.Button("Report Companion Interaction")
|
| 114 |
-
status_box = gr.Textbox(label="Report Status", interactive=False)
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
|
| 121 |
if __name__ == "__main__":
|
| 122 |
demo.launch()
|
|
|
|
| 45 |
|
| 46 |
def respond(self, message, history):
|
| 47 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 48 |
+
for user_msg, bot_msg in history:
|
| 49 |
+
if user_msg:
|
| 50 |
+
messages.append({"role": "user", "content": user_msg})
|
| 51 |
+
if bot_msg:
|
| 52 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 53 |
messages.append({"role": "user", "content": message})
|
| 54 |
|
| 55 |
response = ""
|
|
|
|
| 63 |
token = chunk.choices[0].delta.content
|
| 64 |
if token:
|
| 65 |
response += token
|
| 66 |
+
yield response
|
| 67 |
|
| 68 |
# Save log after full response
|
| 69 |
self.append_to_session_log(message, response)
|
|
|
|
| 105 |
|
| 106 |
# ---- Build Gradio Interface ----
|
| 107 |
with gr.Blocks() as demo:
|
| 108 |
+
chatbot = gr.ChatInterface(fn=create_chatbot(), title="BoundrAI")
|
| 109 |
+
report_btn = gr.Button("Report Companion Interaction")
|
| 110 |
+
status_box = gr.Textbox(label="Report Status", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
def report():
|
| 113 |
+
return chatbot_instance.report_interaction()
|
| 114 |
|
| 115 |
+
report_btn.click(fn=report, outputs=status_box)
|
| 116 |
|
| 117 |
if __name__ == "__main__":
|
| 118 |
demo.launch()
|