Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -120,28 +120,28 @@ with gr.Blocks(title="Infinite Agent", css=open(css_path).read()) as demo:
|
|
| 120 |
#Language selector
|
| 121 |
language = gr.Dropdown(["English", "Svenska", "Türkçe"], label="Choose language", value="English")
|
| 122 |
|
| 123 |
-
#Chatbot
|
| 124 |
chatbot = gr.Chatbot(type="messages", value=[
|
| 125 |
{"role": "system", "content": "🌙 Welcome to Infinite Agent — your guide to emotional clarity, self-worth, and life direction."}
|
| 126 |
])
|
| 127 |
|
| 128 |
-
#Input textbox and clear button
|
| 129 |
msg = gr.Textbox(placeholder="Ask about your emotions, direction, or purpose...")
|
| 130 |
clear = gr.Button("Clear")
|
| 131 |
|
| 132 |
-
#Submit & clear actions
|
| 133 |
msg.submit(chat_with_infinite_agent, [msg, language, chatbot], [chatbot, chatbot])
|
| 134 |
-
clear.click(lambda: [], None, chatbot, queue=False)
|
| 135 |
-
|
| 136 |
-
#
|
| 137 |
-
def api_predict(message, lang="English"):
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
| 146 |
|
| 147 |
demo.launch()
|
|
|
|
| 120 |
#Language selector
|
| 121 |
language = gr.Dropdown(["English", "Svenska", "Türkçe"], label="Choose language", value="English")
|
| 122 |
|
| 123 |
+
#Chatbot
|
| 124 |
chatbot = gr.Chatbot(type="messages", value=[
|
| 125 |
{"role": "system", "content": "🌙 Welcome to Infinite Agent — your guide to emotional clarity, self-worth, and life direction."}
|
| 126 |
])
|
| 127 |
|
|
|
|
| 128 |
msg = gr.Textbox(placeholder="Ask about your emotions, direction, or purpose...")
|
| 129 |
clear = gr.Button("Clear")
|
| 130 |
|
|
|
|
| 131 |
msg.submit(chat_with_infinite_agent, [msg, language, chatbot], [chatbot, chatbot])
|
| 132 |
+
clear.click(lambda: [], None, chatbot, queue=False)
|
| 133 |
+
|
| 134 |
+
#API endpoint
|
| 135 |
+
def api_predict(message, lang="English"):
|
| 136 |
+
history, _ = chat_with_infinite_agent(message, lang, [])
|
| 137 |
+
return history[-1]["content"]
|
| 138 |
+
|
| 139 |
+
#Hidden Interface for /api/predict
|
| 140 |
+
api_interface = gr.Interface(
|
| 141 |
+
fn=api_predict,
|
| 142 |
+
inputs=[gr.Textbox(label="Message"), gr.Textbox(label="Language", value="English")],
|
| 143 |
+
outputs=gr.Textbox(label="Response"),
|
| 144 |
+
allow_flagging="never",
|
| 145 |
+
)
|
| 146 |
|
| 147 |
demo.launch()
|