Spaces:
Sleeping
Sleeping
File size: 2,471 Bytes
b3cc6b6 e730ebb b3cc6b6 64707c8 b3cc6b6 64707c8 e730ebb b3cc6b6 e730ebb b3cc6b6 81d6790 c3cf3a9 dbd4767 e730ebb c3cf3a9 e730ebb 85b56ac b3f00bc 37cffe4 e730ebb 37cffe4 e730ebb 37cffe4 e730ebb 37cffe4 e730ebb 37cffe4 e730ebb 37cffe4 e730ebb 37cffe4 e730ebb 37cffe4 e730ebb c3cf3a9 37cffe4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | import gradio as gr
import pandas as pd
import matplotlib
matplotlib.use("Agg")
import requests
# Charger les artifacts si présents
try:
df_pricing = pd.read_csv("artifacts/pricing_decisions.csv")
ARTIFACTS_OK = True
except Exception:
df_pricing = pd.DataFrame()
ARTIFACTS_OK = False
def analyze_book(title, reviews_text, avg_units_sold):
if not title or not reviews_text:
return "Please enter a title and at least one review.", "", None
url = "https://matteoadam.app.n8n.cloud/webhook-test/price-decider"
payload = {
"title": title,
"reviews": reviews_text,
"avg_units_sold": avg_units_sold,
}
try:
response = requests.post(url, json=payload, timeout=30)
try:
data = response.json()
except Exception:
return (
f"Status code: {response.status_code}\nRaw response:\n{response.text}",
"Non-JSON response",
None,
)
return (
f"Status code: {response.status_code}\nParsed JSON:\n{data}",
f"Type: {type(data).__name__}",
None,
)
except Exception as e:
return f"Error: {str(e)}", "Request failed", None
with gr.Blocks(title="Book Price Decider") as app:
gr.Markdown("# Book Price Decider — Group A4")
gr.Markdown("Sentiment analysis + pricing recommendation")
with gr.Tabs():
with gr.Tab("Dashboard"):
if ARTIFACTS_OK:
gr.Dataframe(value=df_pricing, label="Pricing Decisions Table")
else:
gr.Markdown("No artifacts found yet.")
with gr.Tab("Analyze a New Book"):
title_input = gr.Textbox(label="Book Title")
units_input = gr.Number(label="Avg Monthly Units Sold", value=100)
reviews_input = gr.Textbox(label="Reviews (one per line)", lines=6)
analyze_btn = gr.Button("Analyze")
summary_output = gr.Textbox(label="Summary", lines=6)
details_output = gr.Textbox(label="Details", lines=2)
chart_output = gr.Plot(label="Chart")
analyze_btn.click(
fn=analyze_book,
inputs=[title_input, reviews_input, units_input],
outputs=[summary_output, details_output, chart_output],
)
with gr.Tab("About"):
gr.Markdown("AI for Big Data Management project app.")
app.launch() |