Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,6 +106,10 @@ def chat_with_infinite_agent(message, lang, history):
|
|
| 106 |
#Gradio UI
|
| 107 |
css_path = os.path.join(os.path.dirname(__file__), "style.css")
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
with gr.Blocks(title="Infinite Agent", css=open(css_path).read()) as demo:
|
| 110 |
#Avatar image
|
| 111 |
gr.Image("avatar.png", elem_id="agent-avatar")
|
|
@@ -131,11 +135,7 @@ with gr.Blocks(title="Infinite Agent", css=open(css_path).read()) as demo:
|
|
| 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 |
-
|
| 136 |
-
history, _ = chat_with_infinite_agent(message, lang, [])
|
| 137 |
-
return history[-1]["content"]
|
| 138 |
-
|
| 139 |
-
demo.add_api_route("/api/predict", api_predict, methods=["POST"])
|
| 140 |
|
| 141 |
demo.launch()
|
|
|
|
| 106 |
#Gradio UI
|
| 107 |
css_path = os.path.join(os.path.dirname(__file__), "style.css")
|
| 108 |
|
| 109 |
+
def api_predict(message, lang="English"):
|
| 110 |
+
history, _ = chat_with_infinite_agent(message, lang, [])
|
| 111 |
+
return {"response": history[-1]["content"]}
|
| 112 |
+
|
| 113 |
with gr.Blocks(title="Infinite Agent", css=open(css_path).read()) as demo:
|
| 114 |
#Avatar image
|
| 115 |
gr.Image("avatar.png", elem_id="agent-avatar")
|
|
|
|
| 135 |
msg.submit(chat_with_infinite_agent, [msg, language, chatbot], [chatbot, chatbot])
|
| 136 |
clear.click(lambda: [], None, chatbot, queue=False)
|
| 137 |
|
| 138 |
+
#Expose the custom API endpoint
|
| 139 |
+
gr.api(api_predict, api_name="/api/predict")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
demo.launch()
|