Update app.py
#471
by mohammedff5642 - opened
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -10,14 +11,35 @@ 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 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
print(f"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from huggingface_hub import InferenceClient
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
+
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
+
# Using the free Qwen model to answer evaluation questions
|
| 18 |
+
self.client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 19 |
+
print("Real AI Agent initialized.")
|
| 20 |
+
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
+
print(f"AI processing question: {question[:50]}...")
|
| 23 |
+
|
| 24 |
+
prompt = f"""You are an expert agent competing in the GAIA benchmark.
|
| 25 |
+
Answer the following question in an EXTREMELY concise manner.
|
| 26 |
+
Provide ONLY the final value (a number, a date, a specific name, or a raw word).
|
| 27 |
+
Do NOT write full sentences, do NOT explain your reasoning, and do NOT use conversational text.
|
| 28 |
+
|
| 29 |
+
Question: {question}
|
| 30 |
+
Short Answer:"""
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
messages = [{"role": "user", "content": prompt}]
|
| 34 |
+
response = self.client.chat_completion(messages, max_tokens=50)
|
| 35 |
+
answer = response.choices[0].message.content.strip()
|
| 36 |
+
# Clean up potential artifacts
|
| 37 |
+
answer = answer.replace("FINAL ANSWER:", "").replace('"', '').strip()
|
| 38 |
+
print(f"AI Response: {answer}")
|
| 39 |
+
return answer
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"AI Error: {e}")
|
| 42 |
+
return "Error"
|
| 43 |
|
| 44 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 45 |
"""
|