Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,23 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
with open(meta_file, "w", encoding="utf-8") as f:
|
| 26 |
-
for sample in ds:
|
| 27 |
-
entry = {
|
| 28 |
-
"audio_file": sample["audio_file"],
|
| 29 |
-
"text": sample["text"],
|
| 30 |
-
"speaker_name": sample.get("speaker_name", "speaker")
|
| 31 |
-
}
|
| 32 |
-
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
|
| 33 |
-
|
| 34 |
-
print("✅ Metadata guardada en {meta_file}")
|
| 35 |
-
|
| 36 |
-
# === Iniciar entrenamiento XTTSv2 ===
|
| 37 |
-
print("=== Iniciando entrenamiento XTTSv2 ===")
|
| 38 |
-
try:
|
| 39 |
-
subprocess.run(
|
| 40 |
-
[
|
| 41 |
-
"python",
|
| 42 |
-
"TTS/bin/train_tts.py",
|
| 43 |
-
"--config_path", CONFIG_PATH
|
| 44 |
-
],
|
| 45 |
-
check=True
|
| 46 |
-
)
|
| 47 |
-
except subprocess.CalledProcessError:
|
| 48 |
-
raise RuntimeError("❌ El entrenamiento XTTSv2 falló. Revisa los logs anteriores.")
|
| 49 |
-
|
| 50 |
-
print("=== Entrenamiento finalizado ===")
|
| 51 |
-
|
| 52 |
-
# === Subir modelo fine-tune a Hugging Face ===
|
| 53 |
-
print("=== Subiendo modelo fine-tune a Hugging Face ===")
|
| 54 |
-
api = HfApi()
|
| 55 |
-
api.create_repo(repo_id=HF_REPO_ID, exist_ok=True, token=HF_TOKEN)
|
| 56 |
-
api.upload_folder(
|
| 57 |
-
folder_path=OUTPUT_PATH,
|
| 58 |
-
repo_id=HF_REPO_ID,
|
| 59 |
-
repo_type="model",
|
| 60 |
-
token=HF_TOKEN
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
print("✅ Fine-tuning completado y subido a {HF_REPO_ID}")
|
|
|
|
| 1 |
+
import http.server
|
| 2 |
+
import socketserver
|
| 3 |
+
|
| 4 |
+
# El puerto 7860 es el estándar que usan los Spaces en Hugging Face.
|
| 5 |
+
PORT = 7860
|
| 6 |
+
|
| 7 |
+
# Creamos una clase para manejar las peticiones HTTP
|
| 8 |
+
class MyHandler(http.server.SimpleHTTPRequestHandler):
|
| 9 |
+
def do_GET(self):
|
| 10 |
+
# Envía el código de respuesta 200 (OK)
|
| 11 |
+
self.send_response(200)
|
| 12 |
+
# Establece el tipo de contenido como HTML
|
| 13 |
+
self.send_header("Content-type", "text/html")
|
| 14 |
+
# Finaliza los encabezados de la respuesta
|
| 15 |
+
self.end_headers()
|
| 16 |
+
# Escribe el saludo en la respuesta del servidor
|
| 17 |
+
self.wfile.write(bytes("¡Hola desde mi Space de Docker en Hugging Face! Este servidor usa el módulo nativo de Python.", "utf-8"))
|
| 18 |
+
|
| 19 |
+
# Inicia el servidor.
|
| 20 |
+
# El servidor escuchará en todas las interfaces de red (host='0.0.0.0') en el puerto definido.
|
| 21 |
+
with socketserver.TCPServer(("", PORT), MyHandler) as httpd:
|
| 22 |
+
print(f"Sirviendo en el puerto {PORT}")
|
| 23 |
+
httpd.serve_forever()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|