Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,13 +122,13 @@ agent = CodeAgent(
|
|
| 122 |
|
| 123 |
import gradio as gr
|
| 124 |
|
| 125 |
-
# OLD VERSION
|
| 126 |
-
def run_agent(question):
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
# # NEW VERSION
|
| 134 |
# def run_agent(question):
|
|
@@ -156,6 +156,23 @@ def run_agent(question):
|
|
| 156 |
# except Exception as e:
|
| 157 |
# return [f"Error: {e}"]
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
|
| 161 |
demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
|
|
|
|
| 122 |
|
| 123 |
import gradio as gr
|
| 124 |
|
| 125 |
+
# # OLD VERSION
|
| 126 |
+
# def run_agent(question):
|
| 127 |
+
# try:
|
| 128 |
+
# result = agent(question)
|
| 129 |
+
# return [str(result)] # Must return a list with one string (like ["answer"])
|
| 130 |
+
# except Exception as e:
|
| 131 |
+
# return [f"Error: {e}"]
|
| 132 |
|
| 133 |
# # NEW VERSION
|
| 134 |
# def run_agent(question):
|
|
|
|
| 156 |
# except Exception as e:
|
| 157 |
# return [f"Error: {e}"]
|
| 158 |
|
| 159 |
+
# NEWER VERSION (should just return the result)
|
| 160 |
+
import re
|
| 161 |
+
|
| 162 |
+
def run_agent(question):
|
| 163 |
+
try:
|
| 164 |
+
result = agent(question)
|
| 165 |
+
|
| 166 |
+
# If result is a string and contains "### 1. Task outcome", extract that
|
| 167 |
+
if isinstance(result, str):
|
| 168 |
+
match = re.search(r"### 1\. Task outcome \(short version\):\s*(.+)", result)
|
| 169 |
+
if match:
|
| 170 |
+
return [match.group(1).strip()] # return just the short answer
|
| 171 |
+
return [result.strip()]
|
| 172 |
+
|
| 173 |
+
return [str(result)]
|
| 174 |
+
except Exception as e:
|
| 175 |
+
return [f"Error: {e}"]
|
| 176 |
|
| 177 |
|
| 178 |
demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
|