Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
-
import
|
5 |
from smolagents import OpenAIServerModel, DuckDuckGoSearchTool, CodeAgent, WikipediaSearchTool
|
6 |
from pathlib import Path
|
7 |
import tempfile
|
@@ -11,6 +11,10 @@ from typing import Union, Optional
|
|
11 |
import pandas as pd
|
12 |
from tabulate import tabulate # pragma: no cover – fallback path
|
13 |
import re
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# (Keep Constants as is)
|
16 |
# --- Constants ---
|
@@ -71,6 +75,21 @@ class SpeechToTextTool(PipelineTool):
|
|
71 |
# For response_format="text", `response` is already the raw transcript
|
72 |
return response
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
class ExcelToTextTool(Tool):
|
75 |
"""Render an Excel worksheet as Markdown text."""
|
76 |
|
@@ -172,14 +191,12 @@ def download_file_if_any(base_api_url: str, task_id: str) -> str | None:
|
|
172 |
# --- Basic Agent Definition ---
|
173 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
174 |
|
175 |
-
|
176 |
class BasicAgent:
|
177 |
def __init__(self):
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
additional_authorized_imports=['pandas','numpy','csv','subprocess']
|
183 |
)
|
184 |
|
185 |
print("BasicAgent initialized.")
|
@@ -190,6 +207,24 @@ class BasicAgent:
|
|
190 |
print(f"Agent returning answer: {fixed_answer}")
|
191 |
return fixed_answer
|
192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
194 |
"""
|
195 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
+
import speech_recognition as sr
|
5 |
from smolagents import OpenAIServerModel, DuckDuckGoSearchTool, CodeAgent, WikipediaSearchTool
|
6 |
from pathlib import Path
|
7 |
import tempfile
|
|
|
11 |
import pandas as pd
|
12 |
from tabulate import tabulate # pragma: no cover – fallback path
|
13 |
import re
|
14 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
15 |
+
from langchain.agents import initialize_agent
|
16 |
+
from langchain_community.tools import DuckDuckGoSearchRun, WikipediaQueryRun
|
17 |
+
from langchain_community.llms import HuggingFaceHub
|
18 |
|
19 |
# (Keep Constants as is)
|
20 |
# --- Constants ---
|
|
|
75 |
# For response_format="text", `response` is already the raw transcript
|
76 |
return response
|
77 |
|
78 |
+
def transcribe_audio(audio_file_path):
|
79 |
+
recognizer = sr.Recognizer()
|
80 |
+
with sr.AudioFile(audio_file_path) as source:
|
81 |
+
audio_data = recognizer.record(source)
|
82 |
+
try:
|
83 |
+
text = recognizer.recognize_google(audio_data)
|
84 |
+
return text
|
85 |
+
except sr.UnknownValueError:
|
86 |
+
return "Could not understand audio"
|
87 |
+
except sr.RequestError:
|
88 |
+
return "Could not request results (check internet connection)"
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
class ExcelToTextTool(Tool):
|
94 |
"""Render an Excel worksheet as Markdown text."""
|
95 |
|
|
|
191 |
# --- Basic Agent Definition ---
|
192 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
193 |
|
|
|
194 |
class BasicAgent:
|
195 |
def __init__(self):
|
196 |
+
# Initialize LLM (requires HuggingFace API token)
|
197 |
+
llm = HuggingFaceHub(
|
198 |
+
repo_id="meta-llama/Meta-Llama-3-8B-Instruct" #,
|
199 |
+
# huggingfacehub_api_token="your_token"
|
|
|
200 |
)
|
201 |
|
202 |
print("BasicAgent initialized.")
|
|
|
207 |
print(f"Agent returning answer: {fixed_answer}")
|
208 |
return fixed_answer
|
209 |
|
210 |
+
|
211 |
+
# Initialize tools
|
212 |
+
tools = [
|
213 |
+
DuckDuckGoSearchRun(),
|
214 |
+
WikipediaQueryRun()
|
215 |
+
# Would need custom implementations for other tools
|
216 |
+
]
|
217 |
+
|
218 |
+
self.agent = initialize_agent(
|
219 |
+
tools=tools,
|
220 |
+
llm=llm,
|
221 |
+
agent="zero-shot-react-description",
|
222 |
+
verbose=True
|
223 |
+
)
|
224 |
+
|
225 |
+
def run(self, prompt):
|
226 |
+
return self.agent.run(prompt)
|
227 |
+
|
228 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
229 |
"""
|
230 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|