Spaces:
Sleeping
Sleeping
ostemshaug
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,7 +46,6 @@ mood_to_songs = {
|
|
| 46 |
# ---------- 3. Core logic ----------
|
| 47 |
def analyze_image(image, min_confidence: float = 0.40) -> str:
|
| 48 |
"""Main function: numpy image → markdown text."""
|
| 49 |
-
|
| 50 |
if image is None:
|
| 51 |
return "Please upload a photo with a clear view of your face 🙂"
|
| 52 |
|
|
@@ -82,104 +81,110 @@ def analyze_image(image, min_confidence: float = 0.40) -> str:
|
|
| 82 |
return text
|
| 83 |
|
| 84 |
|
| 85 |
-
# ---------- 4. UI
|
| 86 |
with gr.Blocks() as demo:
|
| 87 |
-
|
| 88 |
-
|
|
|
|
| 89 |
"""
|
| 90 |
-
<style
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
color: #e5e7eb;
|
| 94 |
-
font-family: system-ui, -apple-system, BlinkMacSystemFont,
|
| 95 |
-
|
| 96 |
-
.
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
background: rgba(15,23,42,0.95);
|
| 103 |
-
border-radius: 20px;
|
| 104 |
-
padding: 18px 20px;
|
| 105 |
-
box-shadow: 0 18px 45px rgba(0,0,0,0.45);
|
| 106 |
-
border: 1px solid rgba(148,163,184,0.22);
|
| 107 |
-
}
|
| 108 |
-
.mw-title {
|
| 109 |
-
font-size: 2.1rem;
|
| 110 |
-
font-weight: 700;
|
| 111 |
-
letter-spacing: -0.03em;
|
| 112 |
-
}
|
| 113 |
-
.mw-subtitle {
|
| 114 |
-
opacity: 0.85;
|
| 115 |
-
font-size: 0.95rem;
|
| 116 |
-
}
|
| 117 |
-
.mw-highlight {
|
| 118 |
-
color: #22c55e;
|
| 119 |
-
font-weight: 600;
|
| 120 |
-
}
|
| 121 |
-
.gr-button {
|
| 122 |
-
border-radius: 999px !important;
|
| 123 |
-
background: linear-gradient(135deg, #1DB954, #16a34a) !important;
|
| 124 |
-
color: #0b0f16 !important;
|
| 125 |
-
font-weight: 600 !important;
|
| 126 |
-
border: none !important;
|
| 127 |
-
padding: 0.65rem 1.6rem !important;
|
| 128 |
-
font-size: 0.98rem !important;
|
| 129 |
-
}
|
| 130 |
-
.gr-button:hover {
|
| 131 |
-
filter: brightness(1.04);
|
| 132 |
-
}
|
| 133 |
-
.gr-image img {
|
| 134 |
-
border-radius: 22px !important;
|
| 135 |
-
}
|
| 136 |
-
</style>
|
| 137 |
-
|
| 138 |
-
<div class="mw-card">
|
| 139 |
-
<div class="mw-title">🌊 MoodWave</div>
|
| 140 |
-
<div class="mw-subtitle">
|
| 141 |
-
AI-powered mood-based music recommendations – <span class="mw-highlight">Spotify only</span>
|
| 142 |
</div>
|
| 143 |
-
<p>
|
| 144 |
-
Upload a selfie or any face picture and MoodWave will
|
| 145 |
-
|
| 146 |
-
|
| 147 |
</p>
|
| 148 |
</div>
|
| 149 |
"""
|
| 150 |
)
|
| 151 |
|
| 152 |
with gr.Row():
|
|
|
|
| 153 |
with gr.Column(scale=1):
|
| 154 |
-
gr.
|
| 155 |
"""
|
| 156 |
-
<div
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
</div>
|
| 160 |
"""
|
| 161 |
)
|
| 162 |
image_input = gr.Image(type="numpy", label="Face photo", height=320)
|
| 163 |
-
submit_btn = gr.Button("Analyze mood & suggest Spotify music")
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
with gr.Column(scale=1):
|
| 166 |
-
gr.
|
| 167 |
"""
|
| 168 |
-
<div
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
</div>
|
| 172 |
"""
|
| 173 |
)
|
| 174 |
output_md = gr.Markdown(value="Waiting for an image…")
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
<li>Uses a Hugging Face <code>transformers</code> <b>image-classification pipeline</b></li>
|
| 184 |
<li>Model: <code>trpakov/vit-face-expression</code> (Vision Transformer fine-tuned for facial expressions)</li>
|
| 185 |
<li>The predicted emotion label feeds a simple <b>rule-based recommender</b> (Python dictionary)</li>
|
|
@@ -187,8 +192,8 @@ body {
|
|
| 187 |
<li>All suggestions are <b>Spotify</b> search links for tracks or playlists</li>
|
| 188 |
</ul>
|
| 189 |
</div>
|
| 190 |
-
|
| 191 |
-
|
| 192 |
|
| 193 |
# Wire button to function
|
| 194 |
submit_btn.click(
|
|
|
|
| 46 |
# ---------- 3. Core logic ----------
|
| 47 |
def analyze_image(image, min_confidence: float = 0.40) -> str:
|
| 48 |
"""Main function: numpy image → markdown text."""
|
|
|
|
| 49 |
if image is None:
|
| 50 |
return "Please upload a photo with a clear view of your face 🙂"
|
| 51 |
|
|
|
|
| 81 |
return text
|
| 82 |
|
| 83 |
|
| 84 |
+
# ---------- 4. UI (Spotify x iOS inspired, using inline styles) ----------
|
| 85 |
with gr.Blocks() as demo:
|
| 86 |
+
|
| 87 |
+
# Header card
|
| 88 |
+
gr.HTML(
|
| 89 |
"""
|
| 90 |
+
<div style="
|
| 91 |
+
background: radial-gradient(circle at top left, #1f2933 0, #020617 45%, #020617 100%);
|
| 92 |
+
border-radius: 24px;
|
| 93 |
+
padding: 20px 24px;
|
| 94 |
+
margin: 16px auto 20px auto;
|
| 95 |
+
max-width: 1100px;
|
| 96 |
+
box-shadow: 0 18px 45px rgba(0,0,0,0.6);
|
| 97 |
+
border: 1px solid rgba(148,163,184,0.25);
|
| 98 |
color: #e5e7eb;
|
| 99 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
|
| 100 |
+
">
|
| 101 |
+
<div style="font-size: 2.1rem; font-weight: 700; letter-spacing: -0.03em;">
|
| 102 |
+
🌊 MoodWave
|
| 103 |
+
</div>
|
| 104 |
+
<div style="opacity: 0.85; font-size: 0.95rem; margin-top: 4px;">
|
| 105 |
+
AI-powered mood-based music recommendations –
|
| 106 |
+
<span style="color:#1DB954; font-weight:600;">Spotify only</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
</div>
|
| 108 |
+
<p style="margin-top: 10px; font-size: 0.95rem; line-height: 1.5;">
|
| 109 |
+
Upload a selfie or any face picture and MoodWave will:<br>
|
| 110 |
+
1. Detect your <b>emotion</b> using a pre-trained computer vision model.<br>
|
| 111 |
+
2. Suggest a short <b>Spotify playlist</b> that matches your current vibe.
|
| 112 |
</p>
|
| 113 |
</div>
|
| 114 |
"""
|
| 115 |
)
|
| 116 |
|
| 117 |
with gr.Row():
|
| 118 |
+
# LEFT: upload
|
| 119 |
with gr.Column(scale=1):
|
| 120 |
+
gr.HTML(
|
| 121 |
"""
|
| 122 |
+
<div style="
|
| 123 |
+
background: #111827;
|
| 124 |
+
border-radius: 20px;
|
| 125 |
+
padding: 16px 18px;
|
| 126 |
+
margin: 0 auto 12px auto;
|
| 127 |
+
max-width: 540px;
|
| 128 |
+
box-shadow: 0 12px 32px rgba(0,0,0,0.5);
|
| 129 |
+
border: 1px solid rgba(55,65,81,0.7);
|
| 130 |
+
color: #e5e7eb;
|
| 131 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
|
| 132 |
+
">
|
| 133 |
+
<h3 style="margin: 0 0 4px 0; font-size: 1.1rem;">1. Upload your photo</h3>
|
| 134 |
+
<p style="margin: 0; font-size: 0.9rem; opacity: 0.85;">
|
| 135 |
+
Use a clear face photo (like a profile picture) for better emotion detection.
|
| 136 |
+
</p>
|
| 137 |
</div>
|
| 138 |
"""
|
| 139 |
)
|
| 140 |
image_input = gr.Image(type="numpy", label="Face photo", height=320)
|
|
|
|
| 141 |
|
| 142 |
+
submit_btn = gr.Button(
|
| 143 |
+
"🎧 Analyze mood & suggest Spotify music",
|
| 144 |
+
elem_id="mw-main-button"
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
# RIGHT: result
|
| 148 |
with gr.Column(scale=1):
|
| 149 |
+
gr.HTML(
|
| 150 |
"""
|
| 151 |
+
<div style="
|
| 152 |
+
background: #111827;
|
| 153 |
+
border-radius: 20px;
|
| 154 |
+
padding: 16px 18px;
|
| 155 |
+
margin: 0 auto 12px auto;
|
| 156 |
+
max-width: 540px;
|
| 157 |
+
box-shadow: 0 12px 32px rgba(0,0,0,0.5);
|
| 158 |
+
border: 1px solid rgba(55,65,81,0.7);
|
| 159 |
+
color: #e5e7eb;
|
| 160 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
|
| 161 |
+
">
|
| 162 |
+
<h3 style="margin: 0 0 4px 0; font-size: 1.1rem;">2. Mood & recommendations</h3>
|
| 163 |
+
<p style="margin: 0; font-size: 0.9rem; opacity: 0.85;">
|
| 164 |
+
The detected mood and Spotify suggestions will appear below.
|
| 165 |
+
</p>
|
| 166 |
</div>
|
| 167 |
"""
|
| 168 |
)
|
| 169 |
output_md = gr.Markdown(value="Waiting for an image…")
|
| 170 |
|
| 171 |
+
# Footer / technical card
|
| 172 |
+
gr.HTML(
|
| 173 |
+
"""
|
| 174 |
+
<div style="
|
| 175 |
+
background: #020617;
|
| 176 |
+
border-radius: 20px;
|
| 177 |
+
padding: 16px 18px;
|
| 178 |
+
margin: 8px auto 24px auto;
|
| 179 |
+
max-width: 1100px;
|
| 180 |
+
box-shadow: 0 10px 28px rgba(0,0,0,0.6);
|
| 181 |
+
border: 1px solid rgba(30,64,175,0.6);
|
| 182 |
+
color: #e5e7eb;
|
| 183 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
|
| 184 |
+
font-size: 0.9rem;
|
| 185 |
+
">
|
| 186 |
+
<h4 style="margin-top: 0;">How it works (technical view)</h4>
|
| 187 |
+
<ul style="margin-left: 1.1rem;">
|
| 188 |
<li>Uses a Hugging Face <code>transformers</code> <b>image-classification pipeline</b></li>
|
| 189 |
<li>Model: <code>trpakov/vit-face-expression</code> (Vision Transformer fine-tuned for facial expressions)</li>
|
| 190 |
<li>The predicted emotion label feeds a simple <b>rule-based recommender</b> (Python dictionary)</li>
|
|
|
|
| 192 |
<li>All suggestions are <b>Spotify</b> search links for tracks or playlists</li>
|
| 193 |
</ul>
|
| 194 |
</div>
|
| 195 |
+
"""
|
| 196 |
+
)
|
| 197 |
|
| 198 |
# Wire button to function
|
| 199 |
submit_btn.click(
|