Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,27 @@
|
|
| 1 |
from flask import Flask, request, Response, stream_with_context, jsonify
|
| 2 |
-
from kokoro_onnx import Kokoro
|
| 3 |
import soundfile as sf
|
| 4 |
import io
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
print("--- STARTUP ---")
|
| 9 |
-
# Because we set the ENV variable in Dockerfile, we don't need arguments here!
|
| 10 |
print("Loading Kokoro...")
|
|
|
|
| 11 |
kokoro = Kokoro("kokoro-v1.0.int8.onnx", "voices-v1.0.bin")
|
| 12 |
print("SUCCESS: Model Loaded!")
|
| 13 |
|
|
@@ -15,7 +29,7 @@ print("SUCCESS: Model Loaded!")
|
|
| 15 |
def home():
|
| 16 |
return "Kokoro TTS API is Online!"
|
| 17 |
|
| 18 |
-
# Universal Route (Accepts /v1
|
| 19 |
@app.route("/audio/speech", methods=["POST"])
|
| 20 |
@app.route("/v1/audio/speech", methods=["POST"])
|
| 21 |
def generate_speech():
|
|
|
|
| 1 |
from flask import Flask, request, Response, stream_with_context, jsonify
|
|
|
|
| 2 |
import soundfile as sf
|
| 3 |
import io
|
| 4 |
|
| 5 |
+
# --- CRITICAL FIX FOR HUGGING FACE SPACES ---
|
| 6 |
+
# This "patches" the missing function that causes the crash.
|
| 7 |
+
import phonemizer.backend.espeak.wrapper
|
| 8 |
+
from phonemizer.backend.espeak.wrapper import EspeakWrapper
|
| 9 |
+
|
| 10 |
+
def dummy_set_data_path(path):
|
| 11 |
+
# We ignore this because Docker sets the path automatically
|
| 12 |
+
pass
|
| 13 |
+
|
| 14 |
+
# We force the library to use our dummy function instead of crashing
|
| 15 |
+
EspeakWrapper.set_data_path = dummy_set_data_path
|
| 16 |
+
# --------------------------------------------
|
| 17 |
+
|
| 18 |
+
from kokoro_onnx import Kokoro
|
| 19 |
+
|
| 20 |
app = Flask(__name__)
|
| 21 |
|
| 22 |
print("--- STARTUP ---")
|
|
|
|
| 23 |
print("Loading Kokoro...")
|
| 24 |
+
# Now this line won't crash because we fixed the wrapper above
|
| 25 |
kokoro = Kokoro("kokoro-v1.0.int8.onnx", "voices-v1.0.bin")
|
| 26 |
print("SUCCESS: Model Loaded!")
|
| 27 |
|
|
|
|
| 29 |
def home():
|
| 30 |
return "Kokoro TTS API is Online!"
|
| 31 |
|
| 32 |
+
# Universal Route (Accepts both /v1 and standard paths)
|
| 33 |
@app.route("/audio/speech", methods=["POST"])
|
| 34 |
@app.route("/v1/audio/speech", methods=["POST"])
|
| 35 |
def generate_speech():
|