Update app.py
Browse files
app.py
CHANGED
|
@@ -3,21 +3,36 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
|
|
|
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def __init__(self):
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
@@ -40,7 +55,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 40 |
|
| 41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 42 |
try:
|
| 43 |
-
agent =
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Error instantiating agent: {e}")
|
| 46 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
# --- ADDED BY BEYZAPEHLIVAN ---
|
| 7 |
+
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
+
# --- YENİ ALFRED AJANI ---
|
| 15 |
+
token = os.getenv("HF_TOKEN")
|
| 16 |
+
model = HfApiModel(model_id="meta-llama/Llama-3.1-8B-Instruct", token=token)
|
| 17 |
+
|
| 18 |
+
class AlfredAgent:
|
| 19 |
def __init__(self):
|
| 20 |
+
self.agent = CodeAgent(
|
| 21 |
+
tools=[DuckDuckGoSearchTool()],
|
| 22 |
+
model=model,
|
| 23 |
+
add_base_tools=True
|
| 24 |
+
)
|
| 25 |
+
print("AlfredAgent başarıyla kuruldu.")
|
| 26 |
+
|
| 27 |
def __call__(self, question: str) -> str:
|
| 28 |
+
prompt = f"""Solve this task. Provide ONLY the final answer without any explanation.
|
| 29 |
+
If it's a number, just give the number. If it's a name, just the name.
|
| 30 |
+
Task: {question}"""
|
| 31 |
+
try:
|
| 32 |
+
result = self.agent.run(prompt)
|
| 33 |
+
return str(result).strip()
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return f"Error: {e}"
|
| 36 |
|
| 37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 38 |
"""
|
|
|
|
| 55 |
|
| 56 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 57 |
try:
|
| 58 |
+
agent = AlfredAgent()
|
| 59 |
except Exception as e:
|
| 60 |
print(f"Error instantiating agent: {e}")
|
| 61 |
return f"Error initializing agent: {e}", None
|