zenjoul80 commited on
Commit
18fba22
·
verified ·
1 Parent(s): e528c8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -1,14 +1,16 @@
1
- import os, time, requests, threading, io
 
 
 
 
 
 
 
2
  from flask import Flask, render_template, request, session, send_from_directory, jsonify
3
  from flask_socketio import SocketIO, emit
4
 
5
- # We are switching to gevent for better stability in 2026
6
- from gevent import monkey
7
- monkey.patch_all()
8
-
9
  app = Flask(__name__)
10
  app.config['SECRET_KEY'] = 'suno_modern_2026'
11
- # Using gevent as the engine
12
  socketio = SocketIO(app, cors_allowed_origins="*", async_mode='gevent')
13
 
14
  MUSIC_FOLDER = 'saved_music'
@@ -33,6 +35,7 @@ def callback():
33
  filename = f"{task_id}.mp3"
34
  filepath = os.path.join(MUSIC_FOLDER, filename)
35
  try:
 
36
  r = requests.get(audio_url, timeout=30)
37
  with open(filepath, 'wb') as f:
38
  f.write(r.content)
@@ -65,8 +68,6 @@ def handle_gen(payload):
65
  return
66
 
67
  headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
68
-
69
- # Fix potential nulls
70
  payload['instrumental'] = bool(payload.get('instrumental'))
71
  payload['callBackUrl'] = request.host_url + "callback"
72
 
@@ -87,4 +88,5 @@ def handle_gen(payload):
87
  emit('status', {'msg': f'❌ Connection Error: {str(e)}'})
88
 
89
  if __name__ == '__main__':
90
- socketio.run(app, host="0.0.0.0")
 
 
1
+ from gevent import monkey
2
+ monkey.patch_all() # THIS MUST BE LINE 1, BEFORE ANY OTHER IMPORTS
3
+
4
+ import os
5
+ import time
6
+ import requests
7
+ import threading
8
+ import io
9
  from flask import Flask, render_template, request, session, send_from_directory, jsonify
10
  from flask_socketio import SocketIO, emit
11
 
 
 
 
 
12
  app = Flask(__name__)
13
  app.config['SECRET_KEY'] = 'suno_modern_2026'
 
14
  socketio = SocketIO(app, cors_allowed_origins="*", async_mode='gevent')
15
 
16
  MUSIC_FOLDER = 'saved_music'
 
35
  filename = f"{task_id}.mp3"
36
  filepath = os.path.join(MUSIC_FOLDER, filename)
37
  try:
38
+ # Server-side download
39
  r = requests.get(audio_url, timeout=30)
40
  with open(filepath, 'wb') as f:
41
  f.write(r.content)
 
68
  return
69
 
70
  headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
 
 
71
  payload['instrumental'] = bool(payload.get('instrumental'))
72
  payload['callBackUrl'] = request.host_url + "callback"
73
 
 
88
  emit('status', {'msg': f'❌ Connection Error: {str(e)}'})
89
 
90
  if __name__ == '__main__':
91
+ port = int(os.environ.get("PORT", 5000))
92
+ socketio.run(app, host="0.0.0.0", port=port)