ktara's picture
Create app.py
c90f80c verified
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()