Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -127,7 +127,7 @@ class BasicAgent:
|
|
127 |
|
128 |
elif file_info.endswith(".wav") or file_info.endswith(".mp3"):
|
129 |
print("coso Audio file detected, processing with Whisper")
|
130 |
-
audio_bytes =
|
131 |
if audio_bytes is not None:
|
132 |
transcription = self._transcribe_audio(audio_bytes)
|
133 |
prompt_con_audio = (
|
@@ -264,6 +264,42 @@ def get_or_download_image(file_name: str) -> Image.Image:
|
|
264 |
return None
|
265 |
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
'''
|
268 |
base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
|
269 |
commit_hash = "86620fe7a265fdd074ea8d8c8b7a556a1058b0af"
|
|
|
127 |
|
128 |
elif file_info.endswith(".wav") or file_info.endswith(".mp3"):
|
129 |
print("coso Audio file detected, processing with Whisper")
|
130 |
+
audio_bytes = get_or_download_audio(file_info)
|
131 |
if audio_bytes is not None:
|
132 |
transcription = self._transcribe_audio(audio_bytes)
|
133 |
prompt_con_audio = (
|
|
|
264 |
return None
|
265 |
|
266 |
|
267 |
+
def get_or_download_audio(file_name: str) -> bytes:
|
268 |
+
import os
|
269 |
+
import requests
|
270 |
+
|
271 |
+
file_path = os.path.join("data", file_name)
|
272 |
+
hf_token = os.getenv("HF_TOKEN_READ")
|
273 |
+
|
274 |
+
if not hf_token:
|
275 |
+
print("[ERRORE] HF_TOKEN_READ non trovato. Imposta la variabile d'ambiente HF_TOKEN_READ.")
|
276 |
+
return None
|
277 |
+
|
278 |
+
if not os.path.exists(file_path):
|
279 |
+
print(f"[INFO] File {file_name} non trovato in /data, lo scarico...")
|
280 |
+
|
281 |
+
url = f"https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve/main/2023/validation/{file_name}"
|
282 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
283 |
+
|
284 |
+
try:
|
285 |
+
response = requests.get(url, headers=headers)
|
286 |
+
response.raise_for_status()
|
287 |
+
with open(file_path, "wb") as f:
|
288 |
+
f.write(response.content)
|
289 |
+
print(f"[INFO] Scaricato e salvato in {file_path}")
|
290 |
+
except Exception as e:
|
291 |
+
print(f"[ERRORE] Impossibile scaricare il file audio: {e}")
|
292 |
+
return None
|
293 |
+
|
294 |
+
try:
|
295 |
+
with open(file_path, "rb") as f:
|
296 |
+
return f.read()
|
297 |
+
except Exception as e:
|
298 |
+
print(f"[ERRORE] Impossibile leggere il file audio {file_path}: {e}")
|
299 |
+
return None
|
300 |
+
|
301 |
+
|
302 |
+
|
303 |
'''
|
304 |
base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
|
305 |
commit_hash = "86620fe7a265fdd074ea8d8c8b7a556a1058b0af"
|