-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (29 loc) · 790 Bytes
/
app.py
File metadata and controls
39 lines (29 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import gradio as gr
from poweragent.agent import SimpleAgent
_agent: SimpleAgent | None = None
def get_agent() -> SimpleAgent:
global _agent
if _agent is None:
_agent = SimpleAgent()
return _agent
def predict(message: str, history):
try:
return get_agent().reply(message, history)
except Exception as exc:
return f"Error: {exc}"
demo = gr.ChatInterface(
predict,
examples=[
"Summarize the last messages in memory.",
"What do you remember about my preferences?",
],
chatbot=gr.Chatbot(
height=600,
),
)
if __name__ == "__main__":
demo.launch(
server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
server_port=int(os.getenv("GRADIO_SERVER_PORT", "7860")),
)