Update app.py
Browse files
app.py
CHANGED
@@ -18,20 +18,68 @@ search_tool = DuckDuckGoSearchTool()
|
|
18 |
## TOOL 2
|
19 |
class WikipediaTool(Tool):
|
20 |
name = "wikipedia_search"
|
21 |
-
description = "Search Wikipedia and
|
22 |
inputs = {"query": "string"}
|
23 |
output_type = "string"
|
24 |
-
|
25 |
-
def forward(self, query):
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
30 |
log_output = ""
|
31 |
|
32 |
try:
|
33 |
agent = ToolCallingAgent(
|
34 |
-
tools=[search_tool,
|
35 |
model=InferenceClientModel(model="deepseek-ai/DeepSeek-V3", provider="together"),
|
36 |
max_steps=15,
|
37 |
verbosity_level=0,
|
|
|
18 |
## TOOL 2
|
19 |
class WikipediaTool(Tool):
|
20 |
name = "wikipedia_search"
|
21 |
+
description = "Search Wikipedia for a given topic and return a concise summary."
|
22 |
inputs = {"query": "string"}
|
23 |
output_type = "string"
|
24 |
+
|
25 |
+
def forward(self, query: str) -> str:
|
26 |
+
try:
|
27 |
+
page = wikipedia.page(query)
|
28 |
+
return page.summary[:1000] # truncate to first 1000 characters
|
29 |
+
except wikipedia.exceptions.DisambiguationError as e:
|
30 |
+
return f"Disambiguation: {', '.join(e.options[:5])}"
|
31 |
+
except wikipedia.exceptions.PageError:
|
32 |
+
return "No Wikipedia page found."
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error: {str(e)}"
|
35 |
+
|
36 |
+
## TOOL 3
|
37 |
+
class AudioTranscriptionTool(Tool):
|
38 |
+
name = "audio_transcriber"
|
39 |
+
description = "Transcribes an uploaded audio file to text using Whisper."
|
40 |
+
inputs = {"audio": "audio"}
|
41 |
+
output_type = "string"
|
42 |
+
|
43 |
+
def forward(self, audio: str) -> str:
|
44 |
+
try:
|
45 |
+
model = whisper.load_model("base")
|
46 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
47 |
+
tmp_file.write(audio.read())
|
48 |
+
tmp_file_path = tmp_file.name
|
49 |
+
|
50 |
+
result = model.transcribe(tmp_file_path)
|
51 |
+
os.remove(tmp_file_path)
|
52 |
+
return result["text"]
|
53 |
+
except Exception as e:
|
54 |
+
return f"Transcription failed: {str(e)}"
|
55 |
+
|
56 |
+
## TOOL 4
|
57 |
+
class ExcelReaderTool(Tool):
|
58 |
+
name = "excel_reader"
|
59 |
+
description = "Reads uploaded Excel file and summarizes sheet data."
|
60 |
+
inputs = {"excel": "file"}
|
61 |
+
output_type = "string"
|
62 |
+
|
63 |
+
def forward(self, excel) -> str:
|
64 |
+
try:
|
65 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp_file:
|
66 |
+
tmp_file.write(excel.read())
|
67 |
+
tmp_file_path = tmp_file.name
|
68 |
+
|
69 |
+
df = pd.read_excel(tmp_file_path)
|
70 |
+
summary = df.describe(include="all").to_string()
|
71 |
+
os.remove(tmp_file_path)
|
72 |
+
return f"Summary statistics:\n{summary}"
|
73 |
+
except Exception as e:
|
74 |
+
return f"Failed to read Excel file: {str(e)}"
|
75 |
+
|
76 |
|
77 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
78 |
log_output = ""
|
79 |
|
80 |
try:
|
81 |
agent = ToolCallingAgent(
|
82 |
+
tools=[search_tool, WikipediaTool(), AudioTranscriptionTool(), ExcelReaderTool()],
|
83 |
model=InferenceClientModel(model="deepseek-ai/DeepSeek-V3", provider="together"),
|
84 |
max_steps=15,
|
85 |
verbosity_level=0,
|