Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,16 +4,16 @@ import requests
|
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
from pypdf import PdfReader
|
| 7 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool,
|
| 8 |
|
| 9 |
-
# ১. মডেল সেটআপ
|
| 10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 11 |
-
model =
|
| 12 |
-
model_id="Qwen/Qwen2.5-Coder-
|
| 13 |
token=HF_TOKEN
|
| 14 |
)
|
| 15 |
|
| 16 |
-
# ২. কাস্টম টুলস
|
| 17 |
@tool
|
| 18 |
def read_pdf_content(file_path: str) -> str:
|
| 19 |
"""Reads and extracts text from a PDF file.
|
|
@@ -43,7 +43,7 @@ def inspect_image(file_path: str) -> str:
|
|
| 43 |
except Exception as e:
|
| 44 |
return f"Error reading image: {e}"
|
| 45 |
|
| 46 |
-
# ৩. এজেন্ট
|
| 47 |
gaia_agent = CodeAgent(
|
| 48 |
tools=[DuckDuckGoSearchTool(), read_pdf_content, inspect_image],
|
| 49 |
model=model,
|
|
@@ -57,7 +57,7 @@ def solve_single_task(question: str, file_path: str = None) -> str:
|
|
| 57 |
prompt = f"Question: {question}\n"
|
| 58 |
if file_path:
|
| 59 |
prompt += f"Local file available at: {file_path}\n"
|
| 60 |
-
prompt += "Provide ONLY the concise final answer without explanations or 'FINAL ANSWER' prefix."
|
| 61 |
try:
|
| 62 |
raw = str(gaia_agent.run(prompt)).strip()
|
| 63 |
return re.sub(r'^(FINAL ANSWER|Answer)[:\s]*', '', raw, flags=re.IGNORECASE).strip()
|
|
@@ -66,7 +66,7 @@ def solve_single_task(question: str, file_path: str = None) -> str:
|
|
| 66 |
|
| 67 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 68 |
if not profile:
|
| 69 |
-
return "Please Login to Hugging Face with the button.", None
|
| 70 |
|
| 71 |
username = profile.username
|
| 72 |
space_id = os.getenv("SPACE_ID", "Learnix-AI-Lab/Final_Assignment_Template")
|
|
@@ -106,7 +106,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 106 |
if local_path and os.path.exists(local_path):
|
| 107 |
os.remove(local_path)
|
| 108 |
|
| 109 |
-
# সাবমিট করা
|
| 110 |
submit_data = {
|
| 111 |
"username": username,
|
| 112 |
"agent_code": agent_code,
|
|
@@ -122,7 +121,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 122 |
except Exception as e:
|
| 123 |
return f"Submission error: {e}", display_rows
|
| 124 |
|
| 125 |
-
# ৪. Gradio
|
| 126 |
with gr.Blocks() as demo:
|
| 127 |
gr.Markdown("# 🤖 GAIA Benchmark Evaluator")
|
| 128 |
gr.LoginButton()
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
from pypdf import PdfReader
|
| 7 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, tool
|
| 8 |
|
| 9 |
+
# ১. মডেল সেটআপ (Lightweight & Fast)
|
| 10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 11 |
+
model = InferenceClientModel(
|
| 12 |
+
model_id="Qwen/Qwen2.5-Coder-1.5B-Instruct",
|
| 13 |
token=HF_TOKEN
|
| 14 |
)
|
| 15 |
|
| 16 |
+
# ২. কাস্টম ফাইল রিডার টুলস
|
| 17 |
@tool
|
| 18 |
def read_pdf_content(file_path: str) -> str:
|
| 19 |
"""Reads and extracts text from a PDF file.
|
|
|
|
| 43 |
except Exception as e:
|
| 44 |
return f"Error reading image: {e}"
|
| 45 |
|
| 46 |
+
# ৩. এজেন্ট তৈরি
|
| 47 |
gaia_agent = CodeAgent(
|
| 48 |
tools=[DuckDuckGoSearchTool(), read_pdf_content, inspect_image],
|
| 49 |
model=model,
|
|
|
|
| 57 |
prompt = f"Question: {question}\n"
|
| 58 |
if file_path:
|
| 59 |
prompt += f"Local file available at: {file_path}\n"
|
| 60 |
+
prompt += "Provide ONLY the concise final answer without explanations, reasoning, or 'FINAL ANSWER' prefix."
|
| 61 |
try:
|
| 62 |
raw = str(gaia_agent.run(prompt)).strip()
|
| 63 |
return re.sub(r'^(FINAL ANSWER|Answer)[:\s]*', '', raw, flags=re.IGNORECASE).strip()
|
|
|
|
| 66 |
|
| 67 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 68 |
if not profile:
|
| 69 |
+
return "Please Login to Hugging Face with the button first.", None
|
| 70 |
|
| 71 |
username = profile.username
|
| 72 |
space_id = os.getenv("SPACE_ID", "Learnix-AI-Lab/Final_Assignment_Template")
|
|
|
|
| 106 |
if local_path and os.path.exists(local_path):
|
| 107 |
os.remove(local_path)
|
| 108 |
|
|
|
|
| 109 |
submit_data = {
|
| 110 |
"username": username,
|
| 111 |
"agent_code": agent_code,
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
return f"Submission error: {e}", display_rows
|
| 123 |
|
| 124 |
+
# ৪. Gradio ইন্টারফেস
|
| 125 |
with gr.Blocks() as demo:
|
| 126 |
gr.Markdown("# 🤖 GAIA Benchmark Evaluator")
|
| 127 |
gr.LoginButton()
|