Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,16 +13,16 @@ from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
|
| 13 |
# SECTION 1 — Charger les données pré-calculées
|
| 14 |
# ─────────────────────────────────────────
|
| 15 |
try:
|
| 16 |
-
df_pricing
|
| 17 |
-
df_sales
|
| 18 |
ARTIFACTS_OK = True
|
| 19 |
except Exception:
|
| 20 |
ARTIFACTS_OK = False
|
| 21 |
-
df_pricing
|
| 22 |
-
df_sales
|
| 23 |
|
| 24 |
# ─────────────────────────────────────────
|
| 25 |
-
# SECTION 2 — Analyse en temps réel
|
| 26 |
# ─────────────────────────────────────────
|
| 27 |
analyzer = SentimentIntensityAnalyzer()
|
| 28 |
|
|
@@ -65,101 +65,4 @@ Status code: {response.status_code}
|
|
| 65 |
|
| 66 |
Raw response:
|
| 67 |
```text
|
| 68 |
-
{response.text}
|
| 69 |
-
|
| 70 |
-
# ─────────────────────────────────────────
|
| 71 |
-
# SECTION 3 — Interface Gradio
|
| 72 |
-
# ─────────────────────────────────────────
|
| 73 |
-
with gr.Blocks(title="📚 Book Price Decider", theme=gr.themes.Soft()) as app:
|
| 74 |
-
|
| 75 |
-
gr.Markdown("# 📚 Book Price Decider — Group A4")
|
| 76 |
-
gr.Markdown("Sentiment analysis + ARIMA-based pricing decisions for books.")
|
| 77 |
-
|
| 78 |
-
with gr.Tabs():
|
| 79 |
-
|
| 80 |
-
# ── Tab 1 : Dashboard pré-calculé ──────────────────
|
| 81 |
-
with gr.Tab("📊 Dashboard"):
|
| 82 |
-
gr.Markdown("### Pre-computed results from the analysis notebooks")
|
| 83 |
-
|
| 84 |
-
if ARTIFACTS_OK:
|
| 85 |
-
with gr.Row():
|
| 86 |
-
gr.Image(value="artifacts/sales_trends.png",
|
| 87 |
-
label="Sales Trends")
|
| 88 |
-
gr.Image(value="artifacts/sentiment_distribution.png",
|
| 89 |
-
label="Sentiment Distribution")
|
| 90 |
-
gr.Dataframe(value=df_pricing, label="Pricing Decisions Table")
|
| 91 |
-
else:
|
| 92 |
-
gr.Markdown(
|
| 93 |
-
"⚠️ No artifacts found yet. "
|
| 94 |
-
"Run the notebooks and upload the `artifacts/` folder."
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
# ── Tab 2 : Analyse en temps réel ──────────────────
|
| 98 |
-
with gr.Tab("🔮 Analyze a New Book"):
|
| 99 |
-
gr.Markdown("### Enter book info to get a live pricing recommendation")
|
| 100 |
-
|
| 101 |
-
with gr.Row():
|
| 102 |
-
title_input = gr.Textbox(label="Book Title", placeholder="e.g. The Great Gatsby")
|
| 103 |
-
units_input = gr.Number(label="Avg Monthly Units Sold", value=100)
|
| 104 |
-
|
| 105 |
-
reviews_input = gr.Textbox(
|
| 106 |
-
label="Paste reviews here (one per line)",
|
| 107 |
-
lines=6,
|
| 108 |
-
placeholder="This book was amazing!\nNot what I expected.\nDecent read overall."
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
analyze_btn = gr.Button("🚀 Analyze & Decide", variant="primary")
|
| 112 |
-
|
| 113 |
-
with gr.Row():
|
| 114 |
-
summary_output = gr.Markdown(label="Summary")
|
| 115 |
-
details_output = gr.Textbox(label="Review-by-review labels", lines=6)
|
| 116 |
-
|
| 117 |
-
chart_output = gr.Plot(label="Sentiment Chart")
|
| 118 |
-
|
| 119 |
-
analyze_btn.click(
|
| 120 |
-
fn=analyze_book,
|
| 121 |
-
inputs=[title_input, reviews_input, units_input],
|
| 122 |
-
outputs=[summary_output, details_output, chart_output]
|
| 123 |
-
)
|
| 124 |
-
|
| 125 |
-
# ── Tab 3 : À propos ───────────────────────────────
|
| 126 |
-
with gr.Tab("ℹ️ About"):
|
| 127 |
-
gr.Markdown("""
|
| 128 |
-
## About this app
|
| 129 |
-
|
| 130 |
-
This app is part of the **AI for Big Data Management** group project at ESCP Business School.
|
| 131 |
-
|
| 132 |
-
### Pipeline
|
| 133 |
-
1. **Real-world data** scraped from Books to Scrape
|
| 134 |
-
2. **Synthetic data** generated to enrich with reviews & sales history
|
| 135 |
-
3. **VADER sentiment analysis** on customer reviews
|
| 136 |
-
4. **ARIMA forecasting** on sales time series
|
| 137 |
-
5. **Rule-based pricing decisions** combining sentiment + sales volume
|
| 138 |
-
6. **This Hugging Face app** as the final automation layer
|
| 139 |
-
|
| 140 |
-
### Team — Group A4
|
| 141 |
-
- Project Manager
|
| 142 |
-
- Data Analyst
|
| 143 |
-
- UX Designer(s)
|
| 144 |
-
- Content Specialist
|
| 145 |
-
""")
|
| 146 |
-
## About this app
|
| 147 |
-
|
| 148 |
-
This app is part of the **AI for Big Data Management** group project at ESCP Business School.
|
| 149 |
-
|
| 150 |
-
### Pipeline
|
| 151 |
-
1. **Real-world data** scraped from Books to Scrape
|
| 152 |
-
2. **Synthetic data** generated to enrich with reviews & sales history
|
| 153 |
-
3. **VADER sentiment analysis** on customer reviews
|
| 154 |
-
4. **ARIMA forecasting** on sales time series
|
| 155 |
-
5. **Rule-based pricing decisions** combining sentiment + sales volume
|
| 156 |
-
6. **This Hugging Face app** as the final automation layer
|
| 157 |
-
|
| 158 |
-
### Team — Group A4
|
| 159 |
-
- Project Manager
|
| 160 |
-
- Data Analyst
|
| 161 |
-
- UX Designer(s)
|
| 162 |
-
- Content Specialist
|
| 163 |
-
""")
|
| 164 |
-
|
| 165 |
-
app.launch()
|
|
|
|
| 13 |
# SECTION 1 — Charger les données pré-calculées
|
| 14 |
# ─────────────────────────────────────────
|
| 15 |
try:
|
| 16 |
+
df_pricing = pd.read_csv("artifacts/pricing_decisions.csv")
|
| 17 |
+
df_sales = pd.read_csv("artifacts/dashboard_data.csv")
|
| 18 |
ARTIFACTS_OK = True
|
| 19 |
except Exception:
|
| 20 |
ARTIFACTS_OK = False
|
| 21 |
+
df_pricing = pd.DataFrame()
|
| 22 |
+
df_sales = pd.DataFrame()
|
| 23 |
|
| 24 |
# ─────────────────────────────────────────
|
| 25 |
+
# SECTION 2 — Analyse en temps réel
|
| 26 |
# ─────────────────────────────────────────
|
| 27 |
analyzer = SentimentIntensityAnalyzer()
|
| 28 |
|
|
|
|
| 65 |
|
| 66 |
Raw response:
|
| 67 |
```text
|
| 68 |
+
{response.text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|