Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def analyze_review(review):
|
| 4 |
+
text = review.lower()
|
| 5 |
+
categories = []
|
| 6 |
+
|
| 7 |
+
# Detect categories
|
| 8 |
+
if any(k in text for k in ["broke", "cheap", "rust", "not well made"]):
|
| 9 |
+
categories.append("Product Quality Issues")
|
| 10 |
+
if any(k in text for k in ["battery", "charge", "drain", "slow", "lag"]):
|
| 11 |
+
categories.append("Battery / Performance Issues")
|
| 12 |
+
if any(k in text for k in ["hard to", "difficult", "small screen", "dim", "poor contrast"]):
|
| 13 |
+
categories.append("Usability / Design Problems")
|
| 14 |
+
if any(k in text for k in ["not compatible", "won't load", "can't download", "only works"]):
|
| 15 |
+
categories.append("Compatibility Issues")
|
| 16 |
+
if any(k in text for k in ["not as described", "misleading", "false advertising"]):
|
| 17 |
+
categories.append("Misleading / False Advertising")
|
| 18 |
+
if any(k in text for k in ["install", "setup", "update problem", "software problem"]):
|
| 19 |
+
categories.append("Setup / Installation Problems")
|
| 20 |
+
|
| 21 |
+
# If no category found
|
| 22 |
+
if not categories:
|
| 23 |
+
categories.append("No clear issue detected")
|
| 24 |
+
|
| 25 |
+
# Generate recommendations
|
| 26 |
+
recommendations = []
|
| 27 |
+
|
| 28 |
+
if "Battery / Performance Issues" in categories:
|
| 29 |
+
recommendations.append("Improve battery performance and device stability.")
|
| 30 |
+
if "Product Quality Issues" in categories:
|
| 31 |
+
recommendations.append("Strengthen product quality control and durability.")
|
| 32 |
+
if "Usability / Design Problems" in categories:
|
| 33 |
+
recommendations.append("Improve usability and simplify product design.")
|
| 34 |
+
if "Compatibility Issues" in categories:
|
| 35 |
+
recommendations.append("Clearly communicate compatibility requirements.")
|
| 36 |
+
if "Misleading / False Advertising" in categories:
|
| 37 |
+
recommendations.append("Ensure product descriptions accurately reflect features.")
|
| 38 |
+
if "Setup / Installation Problems" in categories:
|
| 39 |
+
recommendations.append("Provide clearer setup instructions and guidance.")
|
| 40 |
+
|
| 41 |
+
return ", ".join(categories), "\n".join(recommendations)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Create interface
|
| 45 |
+
demo = gr.Interface(
|
| 46 |
+
fn=analyze_review,
|
| 47 |
+
inputs=gr.Textbox(lines=6, placeholder="Paste a customer review here..."),
|
| 48 |
+
outputs=[
|
| 49 |
+
gr.Textbox(label="Detected Issues"),
|
| 50 |
+
gr.Textbox(label="Recommendations")
|
| 51 |
+
],
|
| 52 |
+
title="Amazon Review Issue Analyzer",
|
| 53 |
+
description="Analyze Amazon electronics reviews and get actionable seller recommendations."
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Run app
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
demo.launch()
|