Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,63 +51,21 @@ def analyze_book(title, reviews_text, avg_units_sold):
|
|
| 51 |
|
| 52 |
payload = {
|
| 53 |
"title": title,
|
| 54 |
-
"reviews": reviews_text
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
try:
|
| 58 |
response = requests.post(url, json=payload)
|
| 59 |
-
result = response.json()
|
| 60 |
|
| 61 |
summary = f"""
|
| 62 |
📚 **{title}**
|
| 63 |
|
| 64 |
-
|
| 65 |
-
📊 Sentiment : {result.get("sentiment", "N/A")}
|
| 66 |
-
"""
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
return f"Error: {str(e)}", "N/A", None
|
| 72 |
-
|
| 73 |
-
# Analyse sentiment de chaque review
|
| 74 |
-
lines = [r.strip() for r in reviews_text.strip().split("\n") if r.strip()]
|
| 75 |
-
labels = [get_sentiment_label(line) for line in lines]
|
| 76 |
-
|
| 77 |
-
total = len(labels)
|
| 78 |
-
positive_ratio = labels.count("positive") / total
|
| 79 |
-
negative_ratio = labels.count("negative") / total
|
| 80 |
-
neutral_ratio = labels.count("neutral") / total
|
| 81 |
-
|
| 82 |
-
decision = pricing_decision(avg_units_sold, positive_ratio, negative_ratio)
|
| 83 |
-
|
| 84 |
-
# Résumé texte
|
| 85 |
-
summary = f"""
|
| 86 |
-
📚 **{title}**
|
| 87 |
-
|
| 88 |
-
🔢 Reviews analysées : {total}
|
| 89 |
-
😊 Positive : {positive_ratio:.0%}
|
| 90 |
-
😐 Neutral : {neutral_ratio:.0%}
|
| 91 |
-
😞 Negative : {negative_ratio:.0%}
|
| 92 |
-
📦 Avg units sold : {avg_units_sold}
|
| 93 |
-
|
| 94 |
-
💡 **Pricing Decision : {decision}**
|
| 95 |
-
"""
|
| 96 |
-
|
| 97 |
-
# Graphique en camembert
|
| 98 |
-
fig, ax = plt.subplots(figsize=(4, 4))
|
| 99 |
-
colors = ["#4CAF50", "#FFC107", "#F44336"]
|
| 100 |
-
ax.pie(
|
| 101 |
-
[positive_ratio, neutral_ratio, negative_ratio],
|
| 102 |
-
labels=["Positive", "Neutral", "Negative"],
|
| 103 |
-
autopct="%1.0f%%",
|
| 104 |
-
colors=colors,
|
| 105 |
-
startangle=90
|
| 106 |
-
)
|
| 107 |
-
ax.set_title(f"Sentiment — {title}")
|
| 108 |
-
plt.tight_layout()
|
| 109 |
-
|
| 110 |
-
return summary, "\n".join(f"{l} → {s}" for l, s in zip(lines, labels)), fig
|
| 111 |
|
| 112 |
# ─────────────────────────────────────────
|
| 113 |
# SECTION 3 — Interface Gradio
|
|
|
|
| 51 |
|
| 52 |
payload = {
|
| 53 |
"title": title,
|
| 54 |
+
"reviews": reviews_text,
|
| 55 |
+
"avg_units_sold": avg_units_sold
|
| 56 |
}
|
| 57 |
|
| 58 |
try:
|
| 59 |
response = requests.post(url, json=payload)
|
|
|
|
| 60 |
|
| 61 |
summary = f"""
|
| 62 |
📚 **{title}**
|
| 63 |
|
| 64 |
+
Status code: {response.status_code}
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
Raw response:
|
| 67 |
+
```text
|
| 68 |
+
{response.text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# ─────────────────────────────────────────
|
| 71 |
# SECTION 3 — Interface Gradio
|