Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,6 +47,29 @@ def analyze_book(title, reviews_text, avg_units_sold):
|
|
| 47 |
if not title or not reviews_text:
|
| 48 |
return "⚠️ Please enter a title and at least one review.", "", None
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# Analyse sentiment de chaque review
|
| 51 |
lines = [r.strip() for r in reviews_text.strip().split("\n") if r.strip()]
|
| 52 |
labels = [get_sentiment_label(line) for line in lines]
|
|
|
|
| 47 |
if not title or not reviews_text:
|
| 48 |
return "⚠️ Please enter a title and at least one review.", "", None
|
| 49 |
|
| 50 |
+
url = "https://matteoadam.app.n8n.cloud/webhook-test/price-decider"
|
| 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 |
+
💡 **Pricing Decision : {result.get("pricing_decision", "Error")}**
|
| 65 |
+
📊 Sentiment : {result.get("sentiment", "N/A")}
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
return summary, "Processed via n8n", None
|
| 69 |
+
|
| 70 |
+
except Exception as e:
|
| 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]
|