small improvements and file download bugfix
Browse files- agent.py +2 -1
- app.py +3 -1
- tools/attached_files.py +10 -5
- tools/media.py +4 -2
- utils.py +10 -0
agent.py
CHANGED
|
@@ -18,7 +18,8 @@ def get_agent(provider:str) -> CodeAgent:
|
|
| 18 |
model = LiteLLMModel(
|
| 19 |
model_id="groq/qwen-qwq-32b",
|
| 20 |
api_base="https://api.groq.com/openai/v1/chat/completions",
|
| 21 |
-
api_key=groq_key
|
|
|
|
| 22 |
|
| 23 |
else:
|
| 24 |
model = OpenAIServerModel(
|
|
|
|
| 18 |
model = LiteLLMModel(
|
| 19 |
model_id="groq/qwen-qwq-32b",
|
| 20 |
api_base="https://api.groq.com/openai/v1/chat/completions",
|
| 21 |
+
api_key=groq_key,
|
| 22 |
+
num_ctx=4096)
|
| 23 |
|
| 24 |
else:
|
| 25 |
model = OpenAIServerModel(
|
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import agent
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -72,7 +73,7 @@ def run_random_question(profile: gr.OAuthProfile | None):
|
|
| 72 |
return "Random question is missing task_id or question", None
|
| 73 |
try:
|
| 74 |
with open('system_prompt.txt') as f:
|
| 75 |
-
submitted_answer = agent(f.read()+"\n\n"+question_text)
|
| 76 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 77 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 78 |
except Exception as e:
|
|
@@ -142,6 +143,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 142 |
for item in questions_data:
|
| 143 |
task_id = item.get("task_id")
|
| 144 |
question_text = item.get("question")
|
|
|
|
| 145 |
if not task_id or question_text is None:
|
| 146 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 147 |
continue
|
|
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import agent
|
| 6 |
+
from utils import check_reverse, reverse
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 73 |
return "Random question is missing task_id or question", None
|
| 74 |
try:
|
| 75 |
with open('system_prompt.txt') as f:
|
| 76 |
+
submitted_answer = agent(f.read()+"\n\n"+f"TASK_ID:{task_id}\n"+question_text)
|
| 77 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 78 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 79 |
except Exception as e:
|
|
|
|
| 143 |
for item in questions_data:
|
| 144 |
task_id = item.get("task_id")
|
| 145 |
question_text = item.get("question")
|
| 146 |
+
if check_reverse(question_text): question_text=reverse(question_text)
|
| 147 |
if not task_id or question_text is None:
|
| 148 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 149 |
continue
|
tools/attached_files.py
CHANGED
|
@@ -2,7 +2,8 @@ from smolagents import tool
|
|
| 2 |
import urllib
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
def download_file_from_url(url: str) -> str:
|
| 7 |
"""
|
| 8 |
Download a file from a URL and save it to a temporary location.
|
|
@@ -20,13 +21,15 @@ def download_file_from_url(url: str) -> str:
|
|
| 20 |
return file_path
|
| 21 |
|
| 22 |
@tool
|
| 23 |
-
def csv_reader(
|
| 24 |
"""
|
| 25 |
Extract CSV file content and return it in a json format. Supported file extensions: .csv
|
| 26 |
Args:
|
| 27 |
-
|
| 28 |
"""
|
| 29 |
|
|
|
|
|
|
|
| 30 |
try:
|
| 31 |
df = pd.read_csv(file_path)
|
| 32 |
return df.to_json()
|
|
@@ -35,13 +38,15 @@ def csv_reader(file_path: str) -> str:
|
|
| 35 |
return f"Error analyzing CSV file: {str(e)}"
|
| 36 |
|
| 37 |
@tool
|
| 38 |
-
def excel_reader(
|
| 39 |
"""
|
| 40 |
Extract Excel file content and return it in a json format. Supported file extensions: .xls, .xlsx, .xlsb, .xlsm, .odf, .ods, .odt
|
| 41 |
Args:
|
| 42 |
-
|
| 43 |
"""
|
| 44 |
|
|
|
|
|
|
|
| 45 |
try:
|
| 46 |
df = pd.read_excel(file_path)
|
| 47 |
return df.to_json()
|
|
|
|
| 2 |
import urllib
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
+
FILES_URL = "https://agents-course-unit4-scoring.hf.space/files/"
|
| 6 |
+
|
| 7 |
def download_file_from_url(url: str) -> str:
|
| 8 |
"""
|
| 9 |
Download a file from a URL and save it to a temporary location.
|
|
|
|
| 21 |
return file_path
|
| 22 |
|
| 23 |
@tool
|
| 24 |
+
def csv_reader(task_id: str) -> str:
|
| 25 |
"""
|
| 26 |
Extract CSV file content and return it in a json format. Supported file extensions: .csv
|
| 27 |
Args:
|
| 28 |
+
task_id: the question TASK_ID.
|
| 29 |
"""
|
| 30 |
|
| 31 |
+
file_path = download_file_from_url(FILES_URL+task_id)
|
| 32 |
+
|
| 33 |
try:
|
| 34 |
df = pd.read_csv(file_path)
|
| 35 |
return df.to_json()
|
|
|
|
| 38 |
return f"Error analyzing CSV file: {str(e)}"
|
| 39 |
|
| 40 |
@tool
|
| 41 |
+
def excel_reader(task_id: str) -> str:
|
| 42 |
"""
|
| 43 |
Extract Excel file content and return it in a json format. Supported file extensions: .xls, .xlsx, .xlsb, .xlsm, .odf, .ods, .odt
|
| 44 |
Args:
|
| 45 |
+
task_id: the question TASK_ID.
|
| 46 |
"""
|
| 47 |
|
| 48 |
+
file_path = download_file_from_url(FILES_URL+task_id)
|
| 49 |
+
|
| 50 |
try:
|
| 51 |
df = pd.read_excel(file_path)
|
| 52 |
return df.to_json()
|
tools/media.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
| 1 |
from smolagents import tool
|
| 2 |
import whisper
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
STOCKFISH_API_URL = "https://stockfish.online/api/s/v2.php"
|
| 6 |
MODEL = whisper.load_model("tiny")
|
| 7 |
|
| 8 |
@tool
|
| 9 |
-
def transcribe_audio(
|
| 10 |
"""
|
| 11 |
Extract MP3 file content and return it as text. Supported file extensions: .mp3
|
| 12 |
Args:
|
| 13 |
-
|
| 14 |
"""
|
| 15 |
|
|
|
|
| 16 |
result = None
|
| 17 |
|
| 18 |
try:
|
|
|
|
| 1 |
from smolagents import tool
|
| 2 |
import whisper
|
| 3 |
import requests
|
| 4 |
+
from attached_files import download_file_from_url
|
| 5 |
|
| 6 |
STOCKFISH_API_URL = "https://stockfish.online/api/s/v2.php"
|
| 7 |
MODEL = whisper.load_model("tiny")
|
| 8 |
|
| 9 |
@tool
|
| 10 |
+
def transcribe_audio(task_id: str) -> str:
|
| 11 |
"""
|
| 12 |
Extract MP3 file content and return it as text. Supported file extensions: .mp3
|
| 13 |
Args:
|
| 14 |
+
task_id: the question TASK_ID.
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
file_path = download_file_from_url(FILES_URL+task_id)
|
| 18 |
result = None
|
| 19 |
|
| 20 |
try:
|
utils.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def check_reverse(question:str)->bool:
|
| 2 |
+
return question[0] in ['.','!','?'] and question[-1].isupper()
|
| 3 |
+
|
| 4 |
+
def reverse(question:str)->str:
|
| 5 |
+
return question[::-1]
|
| 6 |
+
|
| 7 |
+
if __name__=='__main__':
|
| 8 |
+
question = '.epA'
|
| 9 |
+
if check_reverse(question):
|
| 10 |
+
print(reverse(question))
|