Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,22 @@ from smolagents import CodeAgent, DuckDuckGoSearchTool
|
|
10 |
|
11 |
# System prompt used by the agent
|
12 |
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question.
|
13 |
-
Report your thoughts, and finish your answer with just the answer — no prefixes like
|
14 |
Your answer should be a number OR as few words as possible OR a comma-separated list of numbers and/or strings.
|
15 |
If you're asked for a number, don’t use commas or units like $ or %, unless specified.
|
16 |
If you're asked for a string, don’t use articles or abbreviations (e.g. for cities), and write digits in plain text unless told otherwise."""
|
17 |
|
18 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
class GeminiFlashModel:
|
22 |
def __init__(self, model_id="gemini-1.5-flash", api_key=None):
|
23 |
genai.configure(api_key=api_key or os.getenv("GEMINI_API_KEY"))
|
@@ -39,19 +47,21 @@ class GeminiFlashModel:
|
|
39 |
|
40 |
try:
|
41 |
response = self.model.generate_content(prompt)
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
except Exception as e:
|
49 |
-
return
|
50 |
-
|
51 |
-
"input_tokens": 0,
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
|
56 |
# Agent wrapper
|
57 |
class MyAgent:
|
@@ -149,10 +159,11 @@ with gr.Blocks() as demo:
|
|
149 |
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
150 |
|
151 |
if __name__ == "__main__":
|
152 |
-
print("
|
153 |
demo.launch(debug=True, share=False)
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
|
|
|
10 |
|
11 |
# System prompt used by the agent
|
12 |
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question.
|
13 |
+
Report your thoughts, and finish your answer with just the answer — no prefixes like "FINAL ANSWER:".
|
14 |
Your answer should be a number OR as few words as possible OR a comma-separated list of numbers and/or strings.
|
15 |
If you're asked for a number, don’t use commas or units like $ or %, unless specified.
|
16 |
If you're asked for a string, don’t use articles or abbreviations (e.g. for cities), and write digits in plain text unless told otherwise."""
|
17 |
|
18 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
19 |
|
20 |
+
# Generation result wrapper to match smolagents expectations
|
21 |
+
class GenerationResult:
|
22 |
+
def __init__(self, content, token_usage=None, input_tokens=0, output_tokens=0):
|
23 |
+
self.content = content
|
24 |
+
self.token_usage = token_usage or {}
|
25 |
+
self.input_tokens = input_tokens
|
26 |
+
self.output_tokens = output_tokens
|
27 |
+
|
28 |
+
# Gemini model wrapper
|
29 |
class GeminiFlashModel:
|
30 |
def __init__(self, model_id="gemini-1.5-flash", api_key=None):
|
31 |
genai.configure(api_key=api_key or os.getenv("GEMINI_API_KEY"))
|
|
|
47 |
|
48 |
try:
|
49 |
response = self.model.generate_content(prompt)
|
50 |
+
text_output = response.text.strip() if hasattr(response, "text") else str(response)
|
51 |
+
|
52 |
+
return GenerationResult(
|
53 |
+
content=text_output,
|
54 |
+
token_usage={"input_tokens": 0, "output_tokens": 0},
|
55 |
+
input_tokens=0,
|
56 |
+
output_tokens=0
|
57 |
+
)
|
58 |
except Exception as e:
|
59 |
+
return GenerationResult(
|
60 |
+
content=f"GENERATION ERROR: {e}",
|
61 |
+
token_usage={"input_tokens": 0, "output_tokens": 0},
|
62 |
+
input_tokens=0,
|
63 |
+
output_tokens=0
|
64 |
+
)
|
65 |
|
66 |
# Agent wrapper
|
67 |
class MyAgent:
|
|
|
159 |
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
160 |
|
161 |
if __name__ == "__main__":
|
162 |
+
print("🔧 App starting...")
|
163 |
demo.launch(debug=True, share=False)
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
+
|