File size: 1,388 Bytes
9e6b347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()