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