File size: 2,468 Bytes
c90f80c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

def analyze_review(review):
    text = review.lower()
    categories = []

    # Detect categories
    if any(k in text for k in ["broke", "cheap", "rust", "not well made"]):
        categories.append("Product Quality Issues")
    if any(k in text for k in ["battery", "charge", "drain", "slow", "lag"]):
        categories.append("Battery / Performance Issues")
    if any(k in text for k in ["hard to", "difficult", "small screen", "dim", "poor contrast"]):
        categories.append("Usability / Design Problems")
    if any(k in text for k in ["not compatible", "won't load", "can't download", "only works"]):
        categories.append("Compatibility Issues")
    if any(k in text for k in ["not as described", "misleading", "false advertising"]):
        categories.append("Misleading / False Advertising")
    if any(k in text for k in ["install", "setup", "update problem", "software problem"]):
        categories.append("Setup / Installation Problems")

    # If no category found
    if not categories:
        categories.append("No clear issue detected")

    # Generate recommendations
    recommendations = []

    if "Battery / Performance Issues" in categories:
        recommendations.append("Improve battery performance and device stability.")
    if "Product Quality Issues" in categories:
        recommendations.append("Strengthen product quality control and durability.")
    if "Usability / Design Problems" in categories:
        recommendations.append("Improve usability and simplify product design.")
    if "Compatibility Issues" in categories:
        recommendations.append("Clearly communicate compatibility requirements.")
    if "Misleading / False Advertising" in categories:
        recommendations.append("Ensure product descriptions accurately reflect features.")
    if "Setup / Installation Problems" in categories:
        recommendations.append("Provide clearer setup instructions and guidance.")

    return ", ".join(categories), "\n".join(recommendations)


# Create interface
demo = gr.Interface(
    fn=analyze_review,
    inputs=gr.Textbox(lines=6, placeholder="Paste a customer review here..."),
    outputs=[
        gr.Textbox(label="Detected Issues"),
        gr.Textbox(label="Recommendations")
    ],
    title="Amazon Review Issue Analyzer",
    description="Analyze Amazon electronics reviews and get actionable seller recommendations."
)

# Run app
if __name__ == "__main__":
    demo.launch()