github-actions[bot]
commited on
Commit
Β·
0de1839
1
Parent(s):
7f974bd
Auto-deploy from GitHub: a1efee9522cf0cb6b23bc5f10e1cbde13ede6474
Browse files- .gitattributes +1 -1
- app.py +51 -1
.gitattributes
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
|
|
| 1 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.flac filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.wav filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.flac filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from flask_cors import CORS
|
|
| 3 |
import sqlite3
|
| 4 |
import os
|
| 5 |
import uuid
|
| 6 |
-
from datetime import datetime
|
| 7 |
from werkzeug.utils import secure_filename
|
| 8 |
import threading
|
| 9 |
import subprocess
|
|
@@ -21,6 +21,9 @@ os.makedirs('temp_dir', exist_ok=True)
|
|
| 21 |
worker_thread = None
|
| 22 |
worker_running = False
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
def init_db():
|
| 25 |
conn = sqlite3.connect('tts_tasks.db')
|
| 26 |
c = conn.cursor()
|
|
@@ -37,6 +40,50 @@ def init_db():
|
|
| 37 |
conn.commit()
|
| 38 |
conn.close()
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def start_worker():
|
| 41 |
"""Start the worker thread if not already running"""
|
| 42 |
global worker_thread, worker_running
|
|
@@ -74,6 +121,9 @@ def worker_loop():
|
|
| 74 |
voice = row['voice'] or '8' # Default voice
|
| 75 |
speed = row['speed'] or 1.0
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
print(f"\n{'='*60}")
|
| 78 |
print(f"π΅ Processing Task: {task_id}")
|
| 79 |
print(f"π Text: {text[:50]}...")
|
|
|
|
| 3 |
import sqlite3
|
| 4 |
import os
|
| 5 |
import uuid
|
| 6 |
+
from datetime import datetime, timedelta
|
| 7 |
from werkzeug.utils import secure_filename
|
| 8 |
import threading
|
| 9 |
import subprocess
|
|
|
|
| 21 |
worker_thread = None
|
| 22 |
worker_running = False
|
| 23 |
|
| 24 |
+
# Cleanup settings
|
| 25 |
+
RETENTION_DAYS = 10 # Delete entries older than this many days
|
| 26 |
+
|
| 27 |
def init_db():
|
| 28 |
conn = sqlite3.connect('tts_tasks.db')
|
| 29 |
c = conn.cursor()
|
|
|
|
| 40 |
conn.commit()
|
| 41 |
conn.close()
|
| 42 |
|
| 43 |
+
def cleanup_old_entries():
|
| 44 |
+
"""Delete entries older than RETENTION_DAYS along with their audio files"""
|
| 45 |
+
cutoff_date = (datetime.now() - timedelta(days=RETENTION_DAYS)).isoformat()
|
| 46 |
+
|
| 47 |
+
print(f"\nπ§Ή Running cleanup for entries older than {RETENTION_DAYS} days...")
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
conn = sqlite3.connect('tts_tasks.db')
|
| 51 |
+
conn.row_factory = sqlite3.Row
|
| 52 |
+
c = conn.cursor()
|
| 53 |
+
|
| 54 |
+
# Find old entries
|
| 55 |
+
c.execute('SELECT id, output_file FROM tasks WHERE created_at < ?', (cutoff_date,))
|
| 56 |
+
old_entries = c.fetchall()
|
| 57 |
+
|
| 58 |
+
if not old_entries:
|
| 59 |
+
print(" No old entries to clean up.")
|
| 60 |
+
conn.close()
|
| 61 |
+
return
|
| 62 |
+
|
| 63 |
+
deleted_count = 0
|
| 64 |
+
for entry in old_entries:
|
| 65 |
+
task_id = entry['id']
|
| 66 |
+
output_file = entry['output_file']
|
| 67 |
+
|
| 68 |
+
# Delete audio file if it exists
|
| 69 |
+
if output_file:
|
| 70 |
+
file_path = os.path.join(UPLOAD_FOLDER, output_file)
|
| 71 |
+
if os.path.exists(file_path):
|
| 72 |
+
os.remove(file_path)
|
| 73 |
+
print(f" ποΈ Deleted audio: {output_file}")
|
| 74 |
+
|
| 75 |
+
# Delete database entry
|
| 76 |
+
c.execute('DELETE FROM tasks WHERE id = ?', (task_id,))
|
| 77 |
+
deleted_count += 1
|
| 78 |
+
|
| 79 |
+
conn.commit()
|
| 80 |
+
conn.close()
|
| 81 |
+
|
| 82 |
+
print(f" β
Cleaned up {deleted_count} old entries.\n")
|
| 83 |
+
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f" β οΈ Cleanup error: {str(e)}\n")
|
| 86 |
+
|
| 87 |
def start_worker():
|
| 88 |
"""Start the worker thread if not already running"""
|
| 89 |
global worker_thread, worker_running
|
|
|
|
| 121 |
voice = row['voice'] or '8' # Default voice
|
| 122 |
speed = row['speed'] or 1.0
|
| 123 |
|
| 124 |
+
# Run cleanup before processing each task
|
| 125 |
+
cleanup_old_entries()
|
| 126 |
+
|
| 127 |
print(f"\n{'='*60}")
|
| 128 |
print(f"π΅ Processing Task: {task_id}")
|
| 129 |
print(f"π Text: {text[:50]}...")
|