Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1076,7 +1076,6 @@ This is the third paragraph.</textarea>
|
|
| 1076 |
progressBar.style.width = '100%';
|
| 1077 |
progressText.textContent = '✅ Model loaded successfully!';
|
| 1078 |
|
| 1079 |
-
// Hide progress after 2 seconds
|
| 1080 |
setTimeout(() => {
|
| 1081 |
progressContainer.style.display = 'none';
|
| 1082 |
}, 2000);
|
|
@@ -1529,6 +1528,31 @@ This is the third paragraph.</textarea>
|
|
| 1529 |
}
|
| 1530 |
}
|
| 1531 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1532 |
// ============================================================
|
| 1533 |
// Initialize
|
| 1534 |
// ============================================================
|
|
@@ -1551,6 +1575,29 @@ This is the third paragraph.</textarea>
|
|
| 1551 |
|
| 1552 |
app = FastAPI(title="VoxForge TTS API")
|
| 1553 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1554 |
# ============================================================
|
| 1555 |
# API ENDPOINTS
|
| 1556 |
# ============================================================
|
|
|
|
| 1076 |
progressBar.style.width = '100%';
|
| 1077 |
progressText.textContent = '✅ Model loaded successfully!';
|
| 1078 |
|
|
|
|
| 1079 |
setTimeout(() => {
|
| 1080 |
progressContainer.style.display = 'none';
|
| 1081 |
}, 2000);
|
|
|
|
| 1528 |
}
|
| 1529 |
}
|
| 1530 |
|
| 1531 |
+
// ============================================================
|
| 1532 |
+
// Auto-load model when page loads (if not loaded)
|
| 1533 |
+
// ============================================================
|
| 1534 |
+
window.addEventListener('load', function() {
|
| 1535 |
+
setTimeout(function() {
|
| 1536 |
+
fetch('/status')
|
| 1537 |
+
.then(r => r.json())
|
| 1538 |
+
.then(data => {
|
| 1539 |
+
if (!data.model_loaded && !data.model_loading) {
|
| 1540 |
+
console.log('🔄 Auto-loading model...');
|
| 1541 |
+
fetch('/load_model', { method: 'POST' })
|
| 1542 |
+
.then(r => r.json())
|
| 1543 |
+
.then(d => {
|
| 1544 |
+
if (d.success) {
|
| 1545 |
+
console.log('✅ Model loaded!');
|
| 1546 |
+
checkModelStatus();
|
| 1547 |
+
}
|
| 1548 |
+
})
|
| 1549 |
+
.catch(err => console.log('Auto-load failed:', err));
|
| 1550 |
+
}
|
| 1551 |
+
})
|
| 1552 |
+
.catch(err => console.log('Status check failed:', err));
|
| 1553 |
+
}, 3000);
|
| 1554 |
+
});
|
| 1555 |
+
|
| 1556 |
// ============================================================
|
| 1557 |
// Initialize
|
| 1558 |
// ============================================================
|
|
|
|
| 1575 |
|
| 1576 |
app = FastAPI(title="VoxForge TTS API")
|
| 1577 |
|
| 1578 |
+
# ============================================================
|
| 1579 |
+
# AUTO-LOAD MODEL ON STARTUP
|
| 1580 |
+
# ============================================================
|
| 1581 |
+
|
| 1582 |
+
@app.on_event("startup")
|
| 1583 |
+
async def startup_event():
|
| 1584 |
+
"""Load model on startup in background"""
|
| 1585 |
+
import threading
|
| 1586 |
+
import time
|
| 1587 |
+
|
| 1588 |
+
def load_in_background():
|
| 1589 |
+
print("⏳ Waiting 3 seconds before loading model...")
|
| 1590 |
+
time.sleep(3)
|
| 1591 |
+
print("🔄 Loading XTTS model in background...")
|
| 1592 |
+
try:
|
| 1593 |
+
tts_engine.get_model()
|
| 1594 |
+
print("✅ Model loaded successfully!")
|
| 1595 |
+
except Exception as e:
|
| 1596 |
+
print(f"⚠️ Model load failed: {str(e)}")
|
| 1597 |
+
|
| 1598 |
+
thread = threading.Thread(target=load_in_background, daemon=True)
|
| 1599 |
+
thread.start()
|
| 1600 |
+
|
| 1601 |
# ============================================================
|
| 1602 |
# API ENDPOINTS
|
| 1603 |
# ============================================================
|