Nick021402 commited on
Commit
9e9cd26
·
verified ·
1 Parent(s): 7873bab

Final Release: Premium Glassmorphism UI & Ansari Bilal Branding

Browse files
Files changed (2) hide show
  1. README.md +16 -8
  2. app.py +181 -122
README.md CHANGED
@@ -11,18 +11,26 @@ license: mit
11
  short_description: Turn your feelings into AI-generated music
12
  ---
13
 
14
- # 🎵 Emotion2Music AI
15
 
16
- **Turn your feelings into music — powered by AI.**
17
 
18
- This app analyzes your mood from a text description and instantly generates a custom music clip that matches your emotional tone.
19
 
20
- ## How It Works
21
 
22
- 1. **Describe your mood** — Type how you're feeling (e.g., *"I feel hopeful but a little sad"*)
23
- 2. **AI detects your emotion** — A fine-tuned DistilRoBERTa model classifies your text into one of 7 emotions
24
- 3. **Music is generated** — Meta's MusicGen creates a unique audio clip matching your detected mood
25
- 4. **Listen & download** — Play the generated track right in the browser
 
 
 
 
 
 
 
 
26
 
27
  ## Supported Emotions
28
 
 
11
  short_description: Turn your feelings into AI-generated music
12
  ---
13
 
14
+ # 🎵 Emotion2Music AI — Final Release
15
 
16
+ **Developed by [Ansari Bilal](https://ansaribilal.com)**
17
 
18
+ Turn your feelings into a cinematic musical experience. This premium application analyzes your complex emotional states and uses Meta's MusicGen to compose a custom soundtrack that resonates with your soul.
19
 
20
+ ## Premium Features
21
 
22
+ - **Advanced Emotional Intelligence** — Uses DistilRoBERTa to detect 7 distinct emotional states with confidence visualization.
23
+ - **Glassmorphism UI** — High-end, responsive interface with deep blurs and mesh gradients.
24
+ - **Adaptive Duration** — Control your composition length (5s - 15s).
25
+ - **Pro Performance** — Built-in ZeroGPU support for near-instant (3s-5s) music generation on Hugging Face PRO.
26
+ - **Queue System** — Robust handling of multiple requests with real-time progress tracking.
27
+
28
+ ## 🛠️ How It Works
29
+
30
+ 1. **Express Yourself** — Describe your current state in the text area.
31
+ 2. **AI Analysis** — The AI identifies your dominant emotion and creates a descriptive musical prompt.
32
+ 3. **Pure Composition** — MusicGen generates High-Fidelity 32kHz audio matching the prompt.
33
+ 4. **Instant Playback** — Listen and download your unique AI-generated track.
34
 
35
  ## Supported Emotions
36
 
app.py CHANGED
@@ -208,98 +208,154 @@ else:
208
 
209
 
210
  # ---------------------------------------------------------------------------
211
- # Custom CSS for premium dark theme
212
  # ---------------------------------------------------------------------------
213
  CUSTOM_CSS = """
214
- /* Global */
 
 
 
 
 
 
 
 
 
 
 
215
  .gradio-container {
216
- max-width: 900px !important;
217
  margin: 0 auto !important;
 
 
218
  }
219
 
220
- /* Header gradient */
221
- #header-text {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  text-align: center;
223
- background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
 
 
 
 
224
  -webkit-background-clip: text;
225
  -webkit-text-fill-color: transparent;
226
- background-clip: text;
227
- font-size: 2.8em !important;
228
  font-weight: 800 !important;
229
- margin-bottom: 0 !important;
230
- padding-bottom: 0 !important;
231
  }
232
 
233
- #subtitle-text {
234
- text-align: center;
235
- font-size: 1.15em !important;
236
- opacity: 0.8;
237
- margin-top: 0 !important;
 
238
  }
239
 
240
- /* Generate button */
241
- #generate-btn {
242
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
243
- border: none !important;
244
- color: white !important;
245
- font-size: 1.1em !important;
246
  font-weight: 600 !important;
247
- padding: 12px 32px !important;
248
- border-radius: 12px !important;
249
- transition: all 0.3s ease !important;
250
- box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4) !important;
251
  }
252
 
253
- #generate-btn:hover {
254
- transform: translateY(-2px) !important;
255
- box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6) !important;
256
  }
257
 
258
- /* Input styling */
259
  #mood-input textarea {
260
- font-size: 1.05em !important;
261
- border-radius: 10px !important;
262
- border: 2px solid rgba(102, 126, 234, 0.3) !important;
263
- transition: border-color 0.3s ease !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  }
265
 
266
- #mood-input textarea:focus {
267
- border-color: #667eea !important;
268
- box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15) !important;
269
  }
270
 
271
- /* Results sections */
272
- #emotion-results {
273
- border-radius: 12px !important;
274
- border: 1px solid rgba(102, 126, 234, 0.2) !important;
275
  }
276
 
277
- #audio-output {
278
- border-radius: 12px !important;
279
- border: 1px solid rgba(102, 126, 234, 0.2) !important;
280
  }
281
 
282
- #gen-info {
283
- border-radius: 12px !important;
284
- opacity: 0.85;
 
285
  }
286
 
287
- /* Duration slider */
288
- #duration-slider input[type="range"] {
289
- accent-color: #667eea !important;
 
 
 
290
  }
291
 
292
- /* Examples section */
293
- .examples-table {
294
- border-radius: 10px !important;
 
 
 
295
  }
296
 
297
- /* Footer */
298
- #footer-text {
299
- text-align: center;
300
- opacity: 0.5;
301
- font-size: 0.85em !important;
302
- margin-top: 20px !important;
303
  }
304
  """
305
 
@@ -313,77 +369,79 @@ theme = gr.themes.Soft(
313
  font=gr.themes.GoogleFont("Inter"),
314
  )
315
 
316
- with gr.Blocks(theme=theme, css=CUSTOM_CSS, title="Emotion2Music AI") as demo:
317
 
318
- # --- Header ---
319
- gr.Markdown("# 🎵 Emotion2Music AI", elem_id="header-text")
320
- gr.Markdown(
321
- "Turn your feelings into a unique AI-generated music track. "
322
- "Just describe your mood and let the AI do the rest.",
323
- elem_id="subtitle-text",
324
- )
325
 
326
- gr.HTML("<hr style='border: 1px solid rgba(102, 126, 234, 0.15); margin: 10px 0 20px 0;'>")
327
-
328
- # --- Input Section ---
329
- with gr.Group():
330
- with gr.Row():
331
- with gr.Column(scale=4):
332
- text_input = gr.Textbox(
333
- label="💭 How are you feeling?",
334
- placeholder="e.g., I feel hopeful but a little anxious about tomorrow...",
335
- lines=3,
336
- max_lines=5,
337
- elem_id="mood-input",
338
- )
339
- with gr.Column(scale=1, min_width=160):
340
  duration_slider = gr.Slider(
341
  minimum=5,
342
  maximum=15,
343
  value=8,
344
  step=1,
345
- label="⏱️ Duration (seconds)",
346
  elem_id="duration-slider",
347
  )
348
 
349
- generate_btn = gr.Button(
350
- "🎶 Generate Music",
351
- variant="primary",
352
- size="lg",
353
- elem_id="generate-btn",
354
- )
355
-
356
- # --- Examples ---
357
- gr.Examples(
358
- examples=[
359
- ["I'm so excited! I just got my dream job and I can't stop smiling!"],
360
- ["I feel really down today, nothing seems to go right..."],
361
- ["Something just jumped out at me and I screamed!"],
362
- ["I'm furious about the injustice I witnessed today."],
363
- ["I feel calm and content, just relaxing at home."],
364
- ["That food was absolutely revolting, I can't believe I tried it."],
365
- ["I feel hopeful but a little anxious about tomorrow."],
366
- ],
367
- inputs=text_input,
368
- label="💡 Try these examples",
369
- )
370
-
371
- gr.HTML("<hr style='border: 1px solid rgba(102, 126, 234, 0.15); margin: 20px 0;'>")
372
 
373
- # --- Output Section ---
374
- with gr.Row():
375
- with gr.Column(scale=1):
376
- emotion_output = gr.Markdown(
377
- label="Emotion Analysis",
378
- value="*Your emotion analysis will appear here...*",
379
- elem_id="emotion-results",
 
 
 
 
 
 
380
  )
381
- with gr.Column(scale=1):
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  audio_output = gr.Audio(
383
- label="🎧 Generated Music",
384
  type="numpy",
385
  elem_id="audio-output",
 
386
  )
 
387
  gen_info = gr.Markdown(
388
  value="",
389
  elem_id="gen-info",
@@ -396,21 +454,22 @@ with gr.Blocks(theme=theme, css=CUSTOM_CSS, title="Emotion2Music AI") as demo:
396
  outputs=[emotion_output, audio_output, gen_info],
397
  )
398
 
399
- # Also trigger on Enter key
400
  text_input.submit(
401
  fn=generate_music,
402
  inputs=[text_input, duration_slider],
403
  outputs=[emotion_output, audio_output, gen_info],
404
  )
405
 
406
- # --- Footer ---
407
- gr.Markdown(
408
- "Built with ❤️ using "
409
- "[DistilRoBERTa](https://huggingface.co/j-hartmann/emotion-english-distilroberta-base) · "
410
- "[MusicGen](https://huggingface.co/facebook/musicgen-small) · "
411
- "[Gradio](https://gradio.app)",
412
- elem_id="footer-text",
413
- )
 
 
414
 
415
  # ---------------------------------------------------------------------------
416
  # Launch
 
208
 
209
 
210
  # ---------------------------------------------------------------------------
211
+ # Custom CSS for Premium Glassmorphism Theme
212
  # ---------------------------------------------------------------------------
213
  CUSTOM_CSS = """
214
+ /* Import modern font */
215
+ @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
216
+
217
+ :root {
218
+ --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
219
+ --glass-bg: rgba(255, 255, 255, 0.03);
220
+ --glass-border: rgba(255, 255, 255, 0.1);
221
+ --text-main: #f8fafc;
222
+ --text-muted: #94a3b8;
223
+ }
224
+
225
+ /* Base Container & Background */
226
  .gradio-container {
227
+ max-width: 1100px !important;
228
  margin: 0 auto !important;
229
+ background: transparent !important;
230
+ font-family: 'Space+Grotesk', sans-serif !important;
231
  }
232
 
233
+ /* Mesh Gradient Background for the whole page */
234
+ body {
235
+ background-color: #05070a !important;
236
+ background-image:
237
+ radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%),
238
+ radial-gradient(at 50% 0%, hsla(225,39%,20%,1) 0, transparent 50%),
239
+ radial-gradient(at 100% 0%, hsla(339,49%,20%,1) 0, transparent 50%) !important;
240
+ background-attachment: fixed !important;
241
+ }
242
+
243
+ /* Glassmorphism Cards */
244
+ .glass-card {
245
+ background: var(--glass-bg) !important;
246
+ backdrop-filter: blur(16px) !important;
247
+ -webkit-backdrop-filter: blur(16px) !important;
248
+ border: 1px solid var(--glass-border) !important;
249
+ border-radius: 24px !important;
250
+ padding: 20px !important;
251
+ box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37) !important;
252
+ transition: transform 0.3s ease, box-shadow 0.3s ease !important;
253
+ }
254
+
255
+ .glass-card:hover {
256
+ box-shadow: 0 12px 48px 0 rgba(0, 0, 0, 0.5) !important;
257
+ }
258
+
259
+ /* Branding & Typography */
260
+ #brand-header {
261
  text-align: center;
262
+ padding: 40px 0;
263
+ }
264
+
265
+ .main-title {
266
+ background: var(--primary-gradient);
267
  -webkit-background-clip: text;
268
  -webkit-text-fill-color: transparent;
269
+ font-size: 3.5rem !important;
 
270
  font-weight: 800 !important;
271
+ letter-spacing: -0.05em !important;
272
+ margin-bottom: 8px !important;
273
  }
274
 
275
+ .creator-tag {
276
+ color: var(--text-muted);
277
+ font-size: 1.1rem !important;
278
+ font-weight: 400 !important;
279
+ letter-spacing: 0.1em !important;
280
+ text-transform: uppercase;
281
  }
282
 
283
+ .creator-link {
284
+ color: #a855f7 !important;
285
+ text-decoration: none !important;
 
 
 
286
  font-weight: 600 !important;
287
+ border-bottom: 2px solid transparent;
288
+ transition: all 0.3s ease;
 
 
289
  }
290
 
291
+ .creator-link:hover {
292
+ border-bottom: 2px solid #a855f7;
293
+ text-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
294
  }
295
 
296
+ /* Component Styling */
297
  #mood-input textarea {
298
+ background: rgba(0, 0, 0, 0.2) !important;
299
+ border: 1px solid var(--glass-border) !important;
300
+ border-radius: 16px !important;
301
+ color: var(--text-main) !important;
302
+ font-size: 1.1rem !important;
303
+ padding: 16px !important;
304
+ }
305
+
306
+ /* Primary Button */
307
+ #generate-btn {
308
+ background: var(--primary-gradient) !important;
309
+ border: none !important;
310
+ border-radius: 16px !important;
311
+ color: white !important;
312
+ font-weight: 700 !important;
313
+ font-size: 1.2rem !important;
314
+ padding: 16px 32px !important;
315
+ cursor: pointer;
316
+ box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3) !important;
317
+ transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
318
  }
319
 
320
+ #generate-btn:hover {
321
+ transform: scale(1.02) translateY(-2px) !important;
322
+ box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5) !important;
323
  }
324
 
325
+ /* Slider styling */
326
+ .slider-container {
327
+ padding-top: 20px !important;
 
328
  }
329
 
330
+ /* Result visualization */
331
+ .emotion-bar-container {
332
+ margin-top: 10px !important;
333
  }
334
 
335
+ /* Audio Player */
336
+ audio {
337
+ width: 100% !important;
338
+ filter: invert(1) hue-rotate(180deg) brightness(1.5);
339
  }
340
 
341
+ /* Footer Styling */
342
+ #footer-area {
343
+ margin-top: 60px;
344
+ padding: 40px;
345
+ border-top: 1px solid var(--glass-border);
346
+ text-align: center;
347
  }
348
 
349
+ .footer-link {
350
+ margin: 0 15px;
351
+ color: var(--text-muted) !important;
352
+ text-decoration: none !important;
353
+ font-size: 0.95rem;
354
+ transition: color 0.3s ease;
355
  }
356
 
357
+ .footer-link:hover {
358
+ color: var(--text-main) !important;
 
 
 
 
359
  }
360
  """
361
 
 
369
  font=gr.themes.GoogleFont("Inter"),
370
  )
371
 
372
+ with gr.Blocks(theme=theme, css=CUSTOM_CSS, title="Emotion2Music AI — Final Release") as demo:
373
 
374
+ # --- Header Branding ---
375
+ with gr.Div(elem_id="brand-header"):
376
+ gr.HTML("""
377
+ <h1 class='main-title'>Emotion2Music AI</h1>
378
+ <p class='creator-tag'>Developed by <a href='https://ansaribilal.com' target='_blank' class='creator-link'>Ansari Bilal</a></p>
379
+ """)
 
380
 
381
+ # --- Layout Grid ---
382
+ with gr.Row():
383
+ # --- LEFT COLUMN: Input & Control ---
384
+ with gr.Column(scale=1, elem_classes="glass-card"):
385
+ gr.Markdown("### 🌑 Step 1: Mood Expression")
386
+ text_input = gr.Textbox(
387
+ label="",
388
+ placeholder="How is your soul feeling right now? Describe it in a sentence...",
389
+ lines=4,
390
+ elem_id="mood-input",
391
+ )
392
+
393
+ with gr.Div(elem_classes="slider-container"):
394
+ gr.Markdown("### ⏱️ Step 2: Duration")
395
  duration_slider = gr.Slider(
396
  minimum=5,
397
  maximum=15,
398
  value=8,
399
  step=1,
400
+ label="",
401
  elem_id="duration-slider",
402
  )
403
 
404
+ generate_btn = gr.Button(
405
+ " COMPOSING MUSIC",
406
+ variant="primary",
407
+ elem_id="generate-btn",
408
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
 
410
+ # Examples within the card
411
+ gr.Markdown("---")
412
+ gr.Markdown("### 💡 Suggestions")
413
+ gr.Examples(
414
+ examples=[
415
+ ["A warm sunset over a quiet ocean, feeling peaceful."],
416
+ ["Thunder crashing in the distance, heart racing with adrenaline."],
417
+ ["Lost in a crowded city, feeling invisible yet hopeful."],
418
+ ["Dancing in the rain like nobody is watching!"],
419
+ ["The silence of an empty house, echoing with memories."]
420
+ ],
421
+ inputs=text_input,
422
+ label="",
423
  )
424
+
425
+ # --- RIGHT COLUMN: Results & Insights ---
426
+ with gr.Column(scale=1, elem_classes="glass-card"):
427
+ gr.Markdown("### 🧠 Step 3: AI Insights")
428
+
429
+ with gr.Div(elem_classes="emotion-bar-container"):
430
+ emotion_output = gr.Markdown(
431
+ value="*Analysis will appear here after detection...*",
432
+ elem_id="emotion-results",
433
+ )
434
+
435
+ gr.Markdown("---")
436
+ gr.Markdown("### 🔊 Step 4: Your Composition")
437
+
438
  audio_output = gr.Audio(
439
+ label="",
440
  type="numpy",
441
  elem_id="audio-output",
442
+ interactive=False,
443
  )
444
+
445
  gen_info = gr.Markdown(
446
  value="",
447
  elem_id="gen-info",
 
454
  outputs=[emotion_output, audio_output, gen_info],
455
  )
456
 
 
457
  text_input.submit(
458
  fn=generate_music,
459
  inputs=[text_input, duration_slider],
460
  outputs=[emotion_output, audio_output, gen_info],
461
  )
462
 
463
+ # --- Footer Branding ---
464
+ with gr.Div(elem_id="footer-area"):
465
+ gr.HTML(f"""
466
+ <p style='color: white; margin-bottom: 20px;'>© 2026 Ansari Bilal. All rights reserved.</p>
467
+ <div style='display: flex; justify-content: center; gap: 20px;'>
468
+ <a href='https://ansaribilal.com' target='_blank' class='footer-link'>Portfolio</a>
469
+ <a href='https://huggingface.co/Nick021402' target='_blank' class='footer-link'>HF Profile</a>
470
+ <a href='mailto:contact@ansaribilal.com' class='footer-link'>Contact</a>
471
+ </div>
472
+ """)
473
 
474
  # ---------------------------------------------------------------------------
475
  # Launch