Update app.py
Browse files
app.py
CHANGED
@@ -443,21 +443,13 @@ language_dict = {
|
|
443 |
}
|
444 |
}
|
445 |
|
446 |
-
def process_audio(file):
|
447 |
-
# Extract the temp file path
|
448 |
-
temp_file_path = file.name
|
449 |
-
|
450 |
-
return create_download_link(temp_file_path) # Return the working download link
|
451 |
-
|
452 |
def create_download_link(audio_path):
|
453 |
if audio_path is None:
|
454 |
return None
|
455 |
-
|
456 |
-
filename = Path(audio_path).name
|
457 |
|
458 |
-
|
459 |
base_url = "https://hivecorp-w-t-p-01.hf.space" # Replace with your Hugging Face Space URL
|
460 |
-
file_url = f"{base_url}/gradio_api/file={audio_path}"
|
461 |
|
462 |
return f"""
|
463 |
<a href="{file_url}" target="_blank" download="{filename}">
|
@@ -469,12 +461,14 @@ async def text_to_speech_edge(text, language_code, speaker, tashkeel_checkbox=Fa
|
|
469 |
# Define the character limit
|
470 |
char_limit = 100000000
|
471 |
if len(text) > char_limit:
|
472 |
-
return f"Error: Use 150,000 Words at a time.
|
473 |
|
474 |
# Get the voice for the selected language and speaker
|
475 |
voice = language_dict[language_code][speaker]
|
476 |
communicate = edge_tts.Communicate(text, voice)
|
477 |
-
|
|
|
|
|
478 |
tmp_path = tmp_file.name
|
479 |
await communicate.save(tmp_path)
|
480 |
|
|
|
443 |
}
|
444 |
}
|
445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
def create_download_link(audio_path):
|
447 |
if audio_path is None:
|
448 |
return None
|
|
|
|
|
449 |
|
450 |
+
filename = Path(audio_path).name
|
451 |
base_url = "https://hivecorp-w-t-p-01.hf.space" # Replace with your Hugging Face Space URL
|
452 |
+
file_url = f"{base_url}/gradio_api/file={audio_path}" # Correct file path
|
453 |
|
454 |
return f"""
|
455 |
<a href="{file_url}" target="_blank" download="{filename}">
|
|
|
461 |
# Define the character limit
|
462 |
char_limit = 100000000
|
463 |
if len(text) > char_limit:
|
464 |
+
return f"Error: Use 150,000 Words at a time.", None, None
|
465 |
|
466 |
# Get the voice for the selected language and speaker
|
467 |
voice = language_dict[language_code][speaker]
|
468 |
communicate = edge_tts.Communicate(text, voice)
|
469 |
+
|
470 |
+
# Create a temporary file inside /tmp/gradio/ (accessible but auto-deleted later)
|
471 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3", dir="/tmp/gradio/") as tmp_file:
|
472 |
tmp_path = tmp_file.name
|
473 |
await communicate.save(tmp_path)
|
474 |
|