Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def analyze_book(title, reviews_text, avg_units_sold):
|
|
| 27 |
if not title or not reviews_text:
|
| 28 |
return "⚠️ Please enter a title and at least one review.", "", None
|
| 29 |
|
| 30 |
-
url = "https://matteoadam.app.n8n.cloud/webhook
|
| 31 |
|
| 32 |
payload = {
|
| 33 |
"title": title,
|
|
@@ -37,14 +37,20 @@ def analyze_book(title, reviews_text, avg_units_sold):
|
|
| 37 |
|
| 38 |
try:
|
| 39 |
response = requests.post(url, json=payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
summary = (
|
| 42 |
f"📚 {title}\n\n"
|
| 43 |
-
f"
|
| 44 |
-
f"
|
| 45 |
)
|
| 46 |
|
| 47 |
-
return summary, "
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
return f"Error: {str(e)}", "Request failed", None
|
|
|
|
| 27 |
if not title or not reviews_text:
|
| 28 |
return "⚠️ Please enter a title and at least one review.", "", None
|
| 29 |
|
| 30 |
+
url = "https://matteoadam.app.n8n.cloud/webhook/price-decider"
|
| 31 |
|
| 32 |
payload = {
|
| 33 |
"title": title,
|
|
|
|
| 37 |
|
| 38 |
try:
|
| 39 |
response = requests.post(url, json=payload)
|
| 40 |
+
data = response.json()
|
| 41 |
+
|
| 42 |
+
if isinstance(data, list) and len(data) > 0:
|
| 43 |
+
result = data[0]
|
| 44 |
+
else:
|
| 45 |
+
result = data
|
| 46 |
|
| 47 |
summary = (
|
| 48 |
f"📚 {title}\n\n"
|
| 49 |
+
f"Pricing Decision: {result.get('pricing_decision', 'Error')}\n"
|
| 50 |
+
f"Sentiment: {result.get('sentiment', 'N/A')}"
|
| 51 |
)
|
| 52 |
|
| 53 |
+
return summary, "Processed via n8n", None
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
return f"Error: {str(e)}", "Request failed", None
|