teszenofficial commited on
Commit
87a06cc
·
verified ·
1 Parent(s): 5a3a762

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -218
app.py DELETED
@@ -1,218 +0,0 @@
1
- from fastapi import FastAPI, UploadFile, File
2
- from fastapi.responses import HTMLResponse, FileResponse, JSONResponse
3
- from pydub import AudioSegment
4
- import os
5
- import uuid
6
-
7
- app = FastAPI()
8
-
9
- UPLOAD_DIR = "uploads"
10
- OUTPUT_DIR = "outputs"
11
- CROSSFADE_MS = 20_000 # 20 segundos estilo Apple Music
12
-
13
- os.makedirs(UPLOAD_DIR, exist_ok=True)
14
- os.makedirs(OUTPUT_DIR, exist_ok=True)
15
-
16
- # ======================
17
- # AUDIO ENGINE
18
- # ======================
19
-
20
- def load_audio(path):
21
- return AudioSegment.from_file(path)
22
-
23
- def smart_crossfade(track_a, track_b):
24
- # Crossfade limpio: una entra, otra sale
25
- return track_a.append(track_b, crossfade=CROSSFADE_MS)
26
-
27
- def build_mix(track_paths):
28
- current = load_audio(track_paths[0])
29
-
30
- for next_path in track_paths[1:]:
31
- next_track = load_audio(next_path)
32
- current = smart_crossfade(current, next_track)
33
-
34
- output_name = f"{uuid.uuid4().hex}.wav"
35
- output_path = os.path.join(OUTPUT_DIR, output_name)
36
- current.export(output_path, format="wav")
37
- return output_name
38
-
39
- # ======================
40
- # WEB UI
41
- # ======================
42
-
43
- @app.get("/", response_class=HTMLResponse)
44
- def index():
45
- return """
46
- <!DOCTYPE html>
47
- <html lang="es">
48
- <head>
49
- <meta charset="UTF-8">
50
- <title>MONX AI</title>
51
-
52
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
53
-
54
- <style>
55
- body {
56
- background: radial-gradient(circle at top, #0f0c29, #302b63, #24243e);
57
- font-family: 'Segoe UI', sans-serif;
58
- color: #fff;
59
- margin: 0;
60
- padding: 0;
61
- }
62
-
63
- .container {
64
- max-width: 520px;
65
- margin: 60px auto;
66
- background: rgba(0,0,0,0.35);
67
- border-radius: 18px;
68
- padding: 32px;
69
- text-align: center;
70
- box-shadow: 0 0 30px rgba(0,0,0,0.6);
71
- }
72
-
73
- h1 {
74
- margin-bottom: 8px;
75
- font-size: 30px;
76
- }
77
-
78
- p {
79
- opacity: 0.8;
80
- font-size: 14px;
81
- }
82
-
83
- .upload-box {
84
- border: 2px dashed #7fdbff;
85
- border-radius: 14px;
86
- padding: 24px;
87
- margin-top: 22px;
88
- cursor: pointer;
89
- transition: 0.2s;
90
- }
91
-
92
- .upload-box:hover {
93
- background: rgba(255,255,255,0.05);
94
- }
95
-
96
- input[type=file] {
97
- display: none;
98
- }
99
-
100
- button {
101
- margin-top: 22px;
102
- background: linear-gradient(135deg, #7fdbff, #4facfe);
103
- color: #000;
104
- border: none;
105
- padding: 14px 22px;
106
- border-radius: 12px;
107
- font-size: 16px;
108
- cursor: pointer;
109
- }
110
-
111
- button:hover {
112
- opacity: 0.9;
113
- }
114
-
115
- .status {
116
- margin-top: 16px;
117
- font-size: 14px;
118
- }
119
-
120
- audio {
121
- margin-top: 22px;
122
- width: 100%;
123
- }
124
- </style>
125
- </head>
126
-
127
- <body>
128
- <div class="container">
129
- <h1><i class="fa-solid fa-wave-square"></i> MONX AI</h1>
130
- <p>Sube 2 a 4 canciones y crea un mix inteligente con crossfade suave</p>
131
-
132
- <label class="upload-box">
133
- <i class="fa-solid fa-cloud-arrow-up fa-2x"></i><br><br>
134
- Seleccionar canciones
135
- <input type="file" id="files" multiple accept=".mp3,.wav">
136
- </label>
137
-
138
- <button onclick="upload()">Crear Mix</button>
139
-
140
- <div class="status" id="status"></div>
141
- <audio id="player" controls></audio>
142
- </div>
143
-
144
- <script>
145
- async function upload() {
146
- const files = document.getElementById("files").files;
147
- const status = document.getElementById("status");
148
- const player = document.getElementById("player");
149
-
150
- if (files.length < 2 || files.length > 4) {
151
- status.innerText = "⚠️ Sube entre 2 y 4 canciones";
152
- return;
153
- }
154
-
155
- const formData = new FormData();
156
- for (let f of files) {
157
- formData.append("files", f);
158
- }
159
-
160
- status.innerText = "⏳ Procesando mix inteligente...";
161
-
162
- const res = await fetch("/upload-mix", {
163
- method: "POST",
164
- body: formData
165
- });
166
-
167
- const data = await res.json();
168
-
169
- if (data.error) {
170
- status.innerText = "❌ " + data.error;
171
- return;
172
- }
173
-
174
- status.innerText = "✅ Mix listo";
175
- player.src = "/download?file=" + data.file;
176
- player.load();
177
- }
178
- </script>
179
-
180
- </body>
181
- </html>
182
- """
183
-
184
- # ======================
185
- # API ENDPOINTS
186
- # ======================
187
-
188
- @app.post("/upload-mix")
189
- async def upload_and_mix(files: list[UploadFile] = File(...)):
190
- if len(files) < 2 or len(files) > 4:
191
- return JSONResponse({"error": "Sube entre 2 y 4 canciones"}, status_code=400)
192
-
193
- paths = []
194
-
195
- for file in files:
196
- ext = file.filename.split(".")[-1].lower()
197
- if ext not in ["mp3", "wav"]:
198
- return JSONResponse({"error": "Formato no soportado"}, status_code=400)
199
-
200
- filename = f"{uuid.uuid4().hex}.{ext}"
201
- path = os.path.join(UPLOAD_DIR, filename)
202
-
203
- with open(path, "wb") as f:
204
- f.write(await file.read())
205
-
206
- paths.append(path)
207
-
208
- output_name = build_mix(paths)
209
-
210
- return {
211
- "message": "Mix generado",
212
- "file": output_name
213
- }
214
-
215
- @app.get("/download")
216
- def download(file: str):
217
- path = os.path.join(OUTPUT_DIR, file)
218
- return FileResponse(path, media_type="audio/wav", filename="monx_ai_mix.wav")