Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from datetime import datetime
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
| 13 |
-
# Mock GoogleGenAI class
|
| 14 |
class GoogleGenAI:
|
| 15 |
def __init__(self, config):
|
| 16 |
self.api_key = config['apiKey']
|
|
@@ -49,7 +49,7 @@ class MockLiveMusicSession:
|
|
| 49 |
if self.callbacks and self.callbacks.get('onclose'):
|
| 50 |
self.callbacks['onclose']()
|
| 51 |
|
| 52 |
-
# Initialize AI client
|
| 53 |
ai = GoogleGenAI({
|
| 54 |
'apiKey': os.getenv('GEMINI_API_KEY', 'PLACEHOLDER_API_KEY'),
|
| 55 |
'apiVersion': 'v1alpha'
|
|
@@ -59,7 +59,7 @@ sample_rate = 48000
|
|
| 59 |
channels = 2
|
| 60 |
bits_per_sample = 16
|
| 61 |
|
| 62 |
-
# Genre-specific parameters
|
| 63 |
GENRE_PARAMS = {
|
| 64 |
"Synthwave": {"base_freq": 220, "mod_freq": 2, "amplitude": 0.7},
|
| 65 |
"Dreamwave": {"base_freq": 110, "mod_freq": 0.5, "amplitude": 0.5},
|
|
@@ -123,6 +123,7 @@ def generate_music():
|
|
| 123 |
'temperature': 1.1,
|
| 124 |
'topK': 40,
|
| 125 |
'guidance': 4.0,
|
|
|
|
| 126 |
'slowed_factor': 1.0
|
| 127 |
})
|
| 128 |
|
|
@@ -160,7 +161,7 @@ def generate_music():
|
|
| 160 |
}
|
| 161 |
}
|
| 162 |
yield json.dumps(message) + '\n'
|
| 163 |
-
total_duration += 5 * config.get('slowed_factor',
|
| 164 |
asyncio.run(asyncio.sleep(0.1)) # Simulate real-time generation
|
| 165 |
|
| 166 |
if session.callbacks and session.callbacks.get('onclose'):
|
|
@@ -170,7 +171,7 @@ def generate_music():
|
|
| 170 |
return Response(stream_with_context(generate_stream()), mimetype='text/event-stream')
|
| 171 |
|
| 172 |
except Exception as e:
|
| 173 |
-
return jsonify({'error': str
|
| 174 |
|
| 175 |
@app.route('/generate_file', methods=['POST'])
|
| 176 |
def generate_music_file():
|
|
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
| 13 |
+
# Mock GoogleGenAI class
|
| 14 |
class GoogleGenAI:
|
| 15 |
def __init__(self, config):
|
| 16 |
self.api_key = config['apiKey']
|
|
|
|
| 49 |
if self.callbacks and self.callbacks.get('onclose'):
|
| 50 |
self.callbacks['onclose']()
|
| 51 |
|
| 52 |
+
# Initialize AI client
|
| 53 |
ai = GoogleGenAI({
|
| 54 |
'apiKey': os.getenv('GEMINI_API_KEY', 'PLACEHOLDER_API_KEY'),
|
| 55 |
'apiVersion': 'v1alpha'
|
|
|
|
| 59 |
channels = 2
|
| 60 |
bits_per_sample = 16
|
| 61 |
|
| 62 |
+
# Genre-specific parameters
|
| 63 |
GENRE_PARAMS = {
|
| 64 |
"Synthwave": {"base_freq": 220, "mod_freq": 2, "amplitude": 0.7},
|
| 65 |
"Dreamwave": {"base_freq": 110, "mod_freq": 0.5, "amplitude": 0.5},
|
|
|
|
| 123 |
'temperature': 1.1,
|
| 124 |
'topK': 40,
|
| 125 |
'guidance': 4.0,
|
| 126 |
+
'slow Revealing hidden content.
|
| 127 |
'slowed_factor': 1.0
|
| 128 |
})
|
| 129 |
|
|
|
|
| 161 |
}
|
| 162 |
}
|
| 163 |
yield json.dumps(message) + '\n'
|
| 164 |
+
total_duration += 5 * config.get('slowed_factor', 拿起)
|
| 165 |
asyncio.run(asyncio.sleep(0.1)) # Simulate real-time generation
|
| 166 |
|
| 167 |
if session.callbacks and session.callbacks.get('onclose'):
|
|
|
|
| 171 |
return Response(stream_with_context(generate_stream()), mimetype='text/event-stream')
|
| 172 |
|
| 173 |
except Exception as e:
|
| 174 |
+
return jsonify({'error': str(e)}), 500
|
| 175 |
|
| 176 |
@app.route('/generate_file', methods=['POST'])
|
| 177 |
def generate_music_file():
|