Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,6 +84,7 @@ def chat_with_infinite_agent(message, lang, history):
|
|
| 84 |
|
| 85 |
#Generate response safely
|
| 86 |
try:
|
|
|
|
| 87 |
response = llm(prompt, max_tokens=512)
|
| 88 |
output = response["choices"][0]["text"].strip()
|
| 89 |
except Exception as e:
|
|
@@ -106,10 +107,6 @@ 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 |
-
def api_predict(message: str, lang: str = "English") -> dict:
|
| 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,7 +132,4 @@ with gr.Blocks(title="Infinite Agent", css=open(css_path).read()) as demo:
|
|
| 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()
|
|
|
|
| 84 |
|
| 85 |
#Generate response safely
|
| 86 |
try:
|
| 87 |
+
llm = get_model()
|
| 88 |
response = llm(prompt, max_tokens=512)
|
| 89 |
output = response["choices"][0]["text"].strip()
|
| 90 |
except Exception as e:
|
|
|
|
| 107 |
#Gradio UI
|
| 108 |
css_path = os.path.join(os.path.dirname(__file__), "style.css")
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
with gr.Blocks(title="Infinite Agent", css=open(css_path).read()) as demo:
|
| 111 |
#Avatar image
|
| 112 |
gr.Image("avatar.png", elem_id="agent-avatar")
|
|
|
|
| 132 |
msg.submit(chat_with_infinite_agent, [msg, language, chatbot], [chatbot, chatbot])
|
| 133 |
clear.click(lambda: [], None, chatbot, queue=False)
|
| 134 |
|
|
|
|
|
|
|
|
|
|
| 135 |
demo.launch()
|