Spaces:
Sleeping
Sleeping
Michael Hu
commited on
Commit
Β·
2d2f2b9
1
Parent(s):
9c8546d
add pre-setup
Browse files
app.py
CHANGED
|
@@ -6,13 +6,45 @@ Handles file upload, processing pipeline, and UI rendering
|
|
| 6 |
import streamlit as st
|
| 7 |
import os
|
| 8 |
import time
|
| 9 |
-
|
| 10 |
from utils.stt import transcribe_audio
|
| 11 |
from utils.translation import translate_text
|
| 12 |
from utils.tts import generate_speech
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Initialize environment configurations
|
| 15 |
-
# load_dotenv()
|
| 16 |
os.makedirs("temp/uploads", exist_ok=True)
|
| 17 |
os.makedirs("temp/outputs", exist_ok=True)
|
| 18 |
|
|
@@ -29,6 +61,7 @@ def configure_page():
|
|
| 29 |
.reportview-container {margin-top: -2em;}
|
| 30 |
#MainMenu {visibility: hidden;}
|
| 31 |
.stDeployButton {display:none;}
|
|
|
|
| 32 |
</style>
|
| 33 |
""", unsafe_allow_html=True)
|
| 34 |
|
|
@@ -55,7 +88,7 @@ def handle_file_processing(upload_path):
|
|
| 55 |
|
| 56 |
# TTS Phase
|
| 57 |
status_text.markdown("π΅ **Generating Chinese Speech...**")
|
| 58 |
-
output_path = generate_speech(chinese_text,language="zh")
|
| 59 |
progress_bar.progress(100)
|
| 60 |
|
| 61 |
# Display results
|
|
@@ -92,6 +125,7 @@ def render_results(english_text, chinese_text, output_path):
|
|
| 92 |
|
| 93 |
def main():
|
| 94 |
"""Main application workflow"""
|
|
|
|
| 95 |
configure_page()
|
| 96 |
st.title("π§ High-Quality Audio Translation System")
|
| 97 |
st.markdown("Upload English Audio β Get Chinese Speech Output")
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
import os
|
| 8 |
import time
|
| 9 |
+
import subprocess
|
| 10 |
from utils.stt import transcribe_audio
|
| 11 |
from utils.translation import translate_text
|
| 12 |
from utils.tts import generate_speech
|
| 13 |
|
| 14 |
+
# Hugging Face Spaces Setup Automation
|
| 15 |
+
def setup_huggingface_space():
|
| 16 |
+
"""Automatically configure Hugging Face Space requirements"""
|
| 17 |
+
st.sidebar.header("Space Configuration")
|
| 18 |
+
|
| 19 |
+
# Check for required system packages
|
| 20 |
+
try:
|
| 21 |
+
subprocess.run(["espeak-ng", "--version"], check=True, capture_output=True)
|
| 22 |
+
except (FileNotFoundError, subprocess.CalledProcessError):
|
| 23 |
+
st.sidebar.error("""
|
| 24 |
+
**Missing System Dependencies!** Add this to your Space settings:
|
| 25 |
+
```txt
|
| 26 |
+
apt-get update && apt-get install -y espeak-ng
|
| 27 |
+
```
|
| 28 |
+
""")
|
| 29 |
+
st.stop()
|
| 30 |
+
|
| 31 |
+
# Verify model files
|
| 32 |
+
model_dir = "./kokoro"
|
| 33 |
+
required_files = [
|
| 34 |
+
f"{model_dir}/kokoro-v0_19.pth",
|
| 35 |
+
f"{model_dir}/voices/af_bella.pt"
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
if not all(os.path.exists(f) for f in required_files):
|
| 39 |
+
st.sidebar.warning("""
|
| 40 |
+
**Missing Model Files!** Add this to your Space settings:
|
| 41 |
+
```txt
|
| 42 |
+
git clone https://huggingface.co/hexgrad/Kokoro-82M ./kokoro
|
| 43 |
+
```
|
| 44 |
+
""")
|
| 45 |
+
st.stop()
|
| 46 |
+
|
| 47 |
# Initialize environment configurations
|
|
|
|
| 48 |
os.makedirs("temp/uploads", exist_ok=True)
|
| 49 |
os.makedirs("temp/outputs", exist_ok=True)
|
| 50 |
|
|
|
|
| 61 |
.reportview-container {margin-top: -2em;}
|
| 62 |
#MainMenu {visibility: hidden;}
|
| 63 |
.stDeployButton {display:none;}
|
| 64 |
+
.stAlert {padding: 20px !important;}
|
| 65 |
</style>
|
| 66 |
""", unsafe_allow_html=True)
|
| 67 |
|
|
|
|
| 88 |
|
| 89 |
# TTS Phase
|
| 90 |
status_text.markdown("π΅ **Generating Chinese Speech...**")
|
| 91 |
+
output_path = generate_speech(chinese_text, language="zh")
|
| 92 |
progress_bar.progress(100)
|
| 93 |
|
| 94 |
# Display results
|
|
|
|
| 125 |
|
| 126 |
def main():
|
| 127 |
"""Main application workflow"""
|
| 128 |
+
setup_huggingface_space() # First-run configuration checks
|
| 129 |
configure_page()
|
| 130 |
st.title("π§ High-Quality Audio Translation System")
|
| 131 |
st.markdown("Upload English Audio β Get Chinese Speech Output")
|