Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,13 +7,18 @@ import nltk
|
|
| 7 |
import srt
|
| 8 |
from pydub import AudioSegment, silence
|
| 9 |
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# 📦 Safe punkt download
|
| 12 |
nltk_data_path = os.path.join(os.path.expanduser("~"), "nltk_data")
|
| 13 |
nltk.download("punkt", download_dir=nltk_data_path)
|
| 14 |
nltk.data.path.append(nltk_data_path)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
async def text_to_speech(text, voice, rate, pitch):
|
| 18 |
if not text.strip():
|
| 19 |
return None, None, "Please enter some text."
|
|
@@ -97,11 +102,14 @@ async def create_demo():
|
|
| 97 |
|
| 98 |
return demo
|
| 99 |
|
| 100 |
-
#
|
| 101 |
-
|
| 102 |
-
nest_asyncio.apply()
|
| 103 |
|
| 104 |
-
|
| 105 |
-
demo
|
| 106 |
-
demo.
|
|
|
|
|
|
|
| 107 |
|
|
|
|
|
|
|
|
|
| 7 |
import srt
|
| 8 |
from pydub import AudioSegment, silence
|
| 9 |
import datetime
|
| 10 |
+
import nest_asyncio
|
| 11 |
+
import threading
|
| 12 |
+
|
| 13 |
+
# Enable nested event loop (required for Spaces)
|
| 14 |
+
nest_asyncio.apply()
|
| 15 |
|
| 16 |
# 📦 Safe punkt download
|
| 17 |
nltk_data_path = os.path.join(os.path.expanduser("~"), "nltk_data")
|
| 18 |
nltk.download("punkt", download_dir=nltk_data_path)
|
| 19 |
nltk.data.path.append(nltk_data_path)
|
| 20 |
|
| 21 |
+
# 🗣️ Text-to-Speech and SRT generator
|
| 22 |
async def text_to_speech(text, voice, rate, pitch):
|
| 23 |
if not text.strip():
|
| 24 |
return None, None, "Please enter some text."
|
|
|
|
| 102 |
|
| 103 |
return demo
|
| 104 |
|
| 105 |
+
# Global demo instance (for Hugging Face Spaces compatibility)
|
| 106 |
+
demo = None
|
|
|
|
| 107 |
|
| 108 |
+
def launch_app():
|
| 109 |
+
global demo
|
| 110 |
+
demo = asyncio.run(create_demo())
|
| 111 |
+
demo.queue()
|
| 112 |
+
demo.launch()
|
| 113 |
|
| 114 |
+
# Start the app in a thread (non-blocking, Space can detect `demo`)
|
| 115 |
+
threading.Thread(target=launch_app).start()
|