Spaces:
Sleeping
Sleeping
ostemshaug
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,17 +82,121 @@ def analyze_image(image, min_confidence: float = 0.40) -> str:
|
|
| 82 |
return text
|
| 83 |
|
| 84 |
|
| 85 |
-
# ---------- 4.
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
| 98 |
demo.launch()
|
|
|
|
| 82 |
return text
|
| 83 |
|
| 84 |
|
| 85 |
+
# ---------- 4. UI with Blocks + inline CSS (Spotify x iOS aesthetic) ----------
|
| 86 |
+
with gr.Blocks() as demo:
|
| 87 |
+
# Global styles + header (inline CSS so it works on older Gradio)
|
| 88 |
+
gr.Markdown(
|
| 89 |
+
"""
|
| 90 |
+
<style>
|
| 91 |
+
body {
|
| 92 |
+
background: radial-gradient(circle at top left, #101418 0, #02040a 45%, #02040a 100%);
|
| 93 |
+
color: #e5e7eb;
|
| 94 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
|
| 95 |
+
}
|
| 96 |
+
.gradio-container {
|
| 97 |
+
max-width: 1100px !important;
|
| 98 |
+
margin: 0 auto !important;
|
| 99 |
+
padding-top: 24px;
|
| 100 |
+
}
|
| 101 |
+
.mw-card {
|
| 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 |
+
<br>1. Detect your <b>emotion</b> using a pre-trained computer vision model.
|
| 146 |
+
<br>2. Suggest a short <b>Spotify playlist</b> that matches your current vibe.
|
| 147 |
+
</p>
|
| 148 |
+
</div>
|
| 149 |
+
"""
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
with gr.Row():
|
| 153 |
+
with gr.Column(scale=1):
|
| 154 |
+
gr.Markdown(
|
| 155 |
+
"""
|
| 156 |
+
<div class="mw-card">
|
| 157 |
+
<h3>1. Upload your photo</h3>
|
| 158 |
+
<p>Use a clear face photo (like a profile picture) for better emotion detection.</p>
|
| 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.Markdown(
|
| 167 |
+
"""
|
| 168 |
+
<div class="mw-card">
|
| 169 |
+
<h3>2. Mood & recommendations</h3>
|
| 170 |
+
<p>The detected mood and Spotify suggestions will appear below.</p>
|
| 171 |
+
</div>
|
| 172 |
+
"""
|
| 173 |
+
)
|
| 174 |
+
output_md = gr.Markdown(value="Waiting for an image…")
|
| 175 |
+
|
| 176 |
+
with gr.Row():
|
| 177 |
+
with gr.Column():
|
| 178 |
+
gr.Markdown(
|
| 179 |
+
"""
|
| 180 |
+
<div class="mw-card">
|
| 181 |
+
<h4>How it works (technical view)</h4>
|
| 182 |
+
<ul>
|
| 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>
|
| 186 |
+
<li>Built with <b>Python + Gradio</b>, deployed on <b>Hugging Face Spaces</b></li>
|
| 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(
|
| 195 |
+
fn=analyze_image,
|
| 196 |
+
inputs=image_input,
|
| 197 |
+
outputs=output_md
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
|
| 201 |
if __name__ == "__main__":
|
| 202 |
demo.launch()
|