Henri2408's picture
add app
9e6b347 verified
import gradio as gr
import numpy as np
def pricing_assistant(rating, sentiment_score, price, negative_share):
demand_score = (rating * 20) + (sentiment_score * 30) - (price * 0.05) - (negative_share * 20)
if rating >= 4.3 and sentiment_score > 0.3 and negative_share < 0.15:
recommendation = "Moderate price increase possible"
elif rating < 3.8 or negative_share > 0.30:
recommendation = "Do not increase price — improve product perception first"
else:
recommendation = "Maintain price and monitor demand"
explanation = (
f"Demand score: {round(demand_score,2)}. "
"Decision based on rating, sentiment, price and negative review share."
)
return demand_score, recommendation, explanation
demo = gr.Interface(
fn=pricing_assistant,
inputs=[
gr.Slider(1,5,value=4,step=0.1,label="Average Rating"),
gr.Slider(-1,1,value=0.2,step=0.05,label="Sentiment Score"),
gr.Number(value=100,label="Price"),
gr.Slider(0,1,value=0.1,step=0.01,label="Negative Review Share")
],
outputs=[
gr.Number(label="Predicted Demand Score"),
gr.Textbox(label="Pricing Recommendation"),
gr.Textbox(label="Explanation")
],
title="Amazon Pricing Assistant",
description="AI tool to recommend pricing based on sentiment and demand drivers."
)
demo.launch()