Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ login(token=os.environ["HUGGINGFACEHUB_API_TOKEN"])
|
|
| 15 |
## TOOL 1
|
| 16 |
search_tool = DuckDuckGoSearchTool()
|
| 17 |
|
|
|
|
| 18 |
class WikipediaTool(Tool):
|
| 19 |
name = "wikipedia_search"
|
| 20 |
description = "Search Wikipedia for a given topic and return a concise summary."
|
|
@@ -36,9 +37,9 @@ class WikipediaTool(Tool):
|
|
| 36 |
return "No Wikipedia page found."
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error: {str(e)}"
|
| 39 |
-
wiki_tool = WikipediaTool()
|
| 40 |
|
| 41 |
-
|
|
|
|
| 42 |
class AudioTranscriptionTool(Tool):
|
| 43 |
name = "audio_transcriber"
|
| 44 |
description = "Transcribes an uploaded audio file to text using Whisper."
|
|
@@ -50,11 +51,11 @@ class AudioTranscriptionTool(Tool):
|
|
| 50 |
}
|
| 51 |
output_type = "string"
|
| 52 |
|
| 53 |
-
def forward(self, audio:
|
| 54 |
try:
|
| 55 |
model = whisper.load_model("base")
|
| 56 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 57 |
-
tmp_file.write(audio
|
| 58 |
tmp_file_path = tmp_file.name
|
| 59 |
|
| 60 |
result = model.transcribe(tmp_file_path)
|
|
@@ -62,25 +63,24 @@ class AudioTranscriptionTool(Tool):
|
|
| 62 |
return result["text"]
|
| 63 |
except Exception as e:
|
| 64 |
return f"Transcription failed: {str(e)}"
|
| 65 |
-
|
| 66 |
|
| 67 |
# --- Tool 3: Excel Reader Tool ---
|
| 68 |
class ExcelReaderTool(Tool):
|
| 69 |
name = "excel_reader"
|
| 70 |
description = "Reads uploaded Excel file and summarizes sheet data."
|
| 71 |
inputs = {
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
}
|
| 76 |
}
|
| 77 |
-
|
| 78 |
output_type = "string"
|
| 79 |
|
| 80 |
-
def forward(self, excel) -> str:
|
| 81 |
try:
|
| 82 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp_file:
|
| 83 |
-
tmp_file.write(excel
|
| 84 |
tmp_file_path = tmp_file.name
|
| 85 |
|
| 86 |
df = pd.read_excel(tmp_file_path)
|
|
@@ -89,7 +89,10 @@ class ExcelReaderTool(Tool):
|
|
| 89 |
return f"Summary statistics:\n{summary}"
|
| 90 |
except Exception as e:
|
| 91 |
return f"Failed to read Excel file: {str(e)}"
|
|
|
|
| 92 |
excel_tool = ExcelReaderTool()
|
|
|
|
|
|
|
| 93 |
|
| 94 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 95 |
log_output = ""
|
|
|
|
| 15 |
## TOOL 1
|
| 16 |
search_tool = DuckDuckGoSearchTool()
|
| 17 |
|
| 18 |
+
# --- Tool 1: Wikipedia Search Tool ---
|
| 19 |
class WikipediaTool(Tool):
|
| 20 |
name = "wikipedia_search"
|
| 21 |
description = "Search Wikipedia for a given topic and return a concise summary."
|
|
|
|
| 37 |
return "No Wikipedia page found."
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error: {str(e)}"
|
|
|
|
| 40 |
|
| 41 |
+
|
| 42 |
+
# --- Tool 2: Audio Transcription Tool (uses whisper base) ---
|
| 43 |
class AudioTranscriptionTool(Tool):
|
| 44 |
name = "audio_transcriber"
|
| 45 |
description = "Transcribes an uploaded audio file to text using Whisper."
|
|
|
|
| 51 |
}
|
| 52 |
output_type = "string"
|
| 53 |
|
| 54 |
+
def forward(self, audio: bytes) -> str:
|
| 55 |
try:
|
| 56 |
model = whisper.load_model("base")
|
| 57 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 58 |
+
tmp_file.write(audio)
|
| 59 |
tmp_file_path = tmp_file.name
|
| 60 |
|
| 61 |
result = model.transcribe(tmp_file_path)
|
|
|
|
| 63 |
return result["text"]
|
| 64 |
except Exception as e:
|
| 65 |
return f"Transcription failed: {str(e)}"
|
| 66 |
+
|
| 67 |
|
| 68 |
# --- Tool 3: Excel Reader Tool ---
|
| 69 |
class ExcelReaderTool(Tool):
|
| 70 |
name = "excel_reader"
|
| 71 |
description = "Reads uploaded Excel file and summarizes sheet data."
|
| 72 |
inputs = {
|
| 73 |
+
"excel": {
|
| 74 |
+
"type": "any",
|
| 75 |
+
"description": "The Excel (.xlsx) file to summarize"
|
| 76 |
}
|
| 77 |
}
|
|
|
|
| 78 |
output_type = "string"
|
| 79 |
|
| 80 |
+
def forward(self, excel: bytes) -> str:
|
| 81 |
try:
|
| 82 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp_file:
|
| 83 |
+
tmp_file.write(excel)
|
| 84 |
tmp_file_path = tmp_file.name
|
| 85 |
|
| 86 |
df = pd.read_excel(tmp_file_path)
|
|
|
|
| 89 |
return f"Summary statistics:\n{summary}"
|
| 90 |
except Exception as e:
|
| 91 |
return f"Failed to read Excel file: {str(e)}"
|
| 92 |
+
|
| 93 |
excel_tool = ExcelReaderTool()
|
| 94 |
+
wiki_tool = WikipediaTool()
|
| 95 |
+
audio_tool = AudioTranscriptionTool()
|
| 96 |
|
| 97 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 98 |
log_output = ""
|