Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# --- Dummy data (replace later if needed) ---
|
| 6 |
+
np.random.seed(42)
|
| 7 |
+
data = pd.DataFrame({
|
| 8 |
+
"track": [f"Track {i}" for i in range(1, 21)],
|
| 9 |
+
"sentiment": np.random.uniform(-1, 1, 20),
|
| 10 |
+
"streams": np.random.randint(1000, 100000, 20),
|
| 11 |
+
"price": np.random.uniform(5, 15, 20)
|
| 12 |
+
})
|
| 13 |
+
|
| 14 |
+
# --- Functions ---
|
| 15 |
+
def sentiment_analysis():
|
| 16 |
+
avg_sentiment = data["sentiment"].mean()
|
| 17 |
+
return f"Average sentiment score: {round(avg_sentiment, 3)}"
|
| 18 |
+
|
| 19 |
+
def forecast_streams():
|
| 20 |
+
forecast = int(data["streams"].mean() * 1.1)
|
| 21 |
+
return f"Predicted average streams next period: {forecast}"
|
| 22 |
+
|
| 23 |
+
def pricing_recommendation():
|
| 24 |
+
avg_price = data["price"].mean()
|
| 25 |
+
if avg_price > 10:
|
| 26 |
+
return "Recommendation: Consider lowering price to improve conversion."
|
| 27 |
+
else:
|
| 28 |
+
return "Recommendation: Pricing is competitive."
|
| 29 |
+
|
| 30 |
+
# --- UI ---
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# 🎧 Music Streaming Analytics App")
|
| 33 |
+
gr.Markdown("Optimize playlist curation and subscription pricing using sentiment + forecasting")
|
| 34 |
+
|
| 35 |
+
with gr.Tab("Sentiment Insights"):
|
| 36 |
+
btn1 = gr.Button("Analyze Sentiment")
|
| 37 |
+
out1 = gr.Textbox()
|
| 38 |
+
btn1.click(fn=sentiment_analysis, outputs=out1)
|
| 39 |
+
|
| 40 |
+
with gr.Tab("Stream Forecast"):
|
| 41 |
+
btn2 = gr.Button("Forecast Streams")
|
| 42 |
+
out2 = gr.Textbox()
|
| 43 |
+
btn2.click(fn=forecast_streams, outputs=out2)
|
| 44 |
+
|
| 45 |
+
with gr.Tab("Pricing Strategy"):
|
| 46 |
+
btn3 = gr.Button("Get Pricing Recommendation")
|
| 47 |
+
out3 = gr.Textbox()
|
| 48 |
+
btn3.click(fn=pricing_recommendation, outputs=out3)
|
| 49 |
+
|
| 50 |
+
demo.launch()
|