Manish014 commited on
Commit
b723159
Β·
verified Β·
1 Parent(s): ba64767

new updates

Browse files
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load both summarization and sentiment models
5
  summarizer = pipeline(
6
  "summarization",
7
  model="Manish014/review-summariser-gpt-config1",
@@ -14,8 +14,8 @@ sentiment_analyzer = pipeline("sentiment-analysis")
14
  # Inference function
15
  def analyze_review(text):
16
  if not text.strip():
17
- return "Please enter a review.", "Sentiment unavailable."
18
-
19
  summary = summarizer(
20
  text,
21
  max_length=80,
@@ -26,41 +26,50 @@ def analyze_review(text):
26
  )[0]["summary_text"]
27
 
28
  sentiment = sentiment_analyzer(text)[0]
29
- sentiment_output = f"{sentiment['label']} ({round(sentiment['score'] * 100, 2)}%)"
30
 
31
- return summary, sentiment_output
32
 
33
- # Example reviews
34
- example_reviews = [
35
  ["This product leaks water and smells like burnt plastic."],
36
  ["Absolutely loved the screen resolution and battery life."],
37
- ["Worst purchase I've made. Do not recommend at all."]
 
 
38
  ]
39
 
40
- # Build Gradio UI
41
  with gr.Blocks(theme=gr.themes.Base()) as demo:
42
  gr.Markdown("## πŸ“ Review Summariser GPT - Config 1")
43
- gr.Markdown("Enter a long product review below to get a helpful short summary and sentiment prediction.")
 
 
 
44
 
45
  with gr.Row():
46
- input_box = gr.Textbox(label="πŸ—£οΈ Product Review", lines=5, placeholder="Write your detailed review here...")
 
47
 
48
  with gr.Row():
49
- summary_output = gr.Textbox(label="βœ‚οΈ Summary")
50
- sentiment_output = gr.Textbox(label="πŸ“Š Sentiment")
51
 
52
- submit_btn = gr.Button("πŸ” Analyze Review")
53
- clear_btn = gr.Button("🧹 Clear")
54
 
55
- submit_btn.click(analyze_review, inputs=input_box, outputs=[summary_output, sentiment_output])
56
- clear_btn.click(lambda: ("", "", ""), outputs=[input_box, summary_output, sentiment_output])
57
 
58
- gr.Examples(
59
- examples=example_reviews,
60
- inputs=input_box,
61
- label="πŸ” Try an Example"
62
- )
 
 
 
 
63
 
64
- # Run the app
65
  if __name__ == "__main__":
66
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load models
5
  summarizer = pipeline(
6
  "summarization",
7
  model="Manish014/review-summariser-gpt-config1",
 
14
  # Inference function
15
  def analyze_review(text):
16
  if not text.strip():
17
+ return "❗ Please enter a product review.", "❗ Sentiment unavailable."
18
+
19
  summary = summarizer(
20
  text,
21
  max_length=80,
 
26
  )[0]["summary_text"]
27
 
28
  sentiment = sentiment_analyzer(text)[0]
29
+ sentiment_label = f"{sentiment['label']} ({round(sentiment['score'] * 100, 2)}%)"
30
 
31
+ return summary, sentiment_label
32
 
33
+ # Example inputs
34
+ examples = [
35
  ["This product leaks water and smells like burnt plastic."],
36
  ["Absolutely loved the screen resolution and battery life."],
37
+ ["Worst purchase I've made. Do not recommend at all."],
38
+ ["The headphones are okay. Battery is good but fit is not comfortable."],
39
+ ["The fan is extremely loud and doesn't cool much."]
40
  ]
41
 
42
+ # Build UI
43
  with gr.Blocks(theme=gr.themes.Base()) as demo:
44
  gr.Markdown("## πŸ“ Review Summariser GPT - Config 1")
45
+ gr.Markdown("Enter a detailed product review below to receive a helpful summary βœ‚οΈ and predicted sentiment πŸ“Š.")
46
+
47
+ with gr.Row():
48
+ review_input = gr.Textbox(label="πŸ—£οΈ Product Review", lines=5, placeholder="Write your review here...")
49
 
50
  with gr.Row():
51
+ summary_output = gr.Textbox(label="βœ‚οΈ Summary", lines=2)
52
+ sentiment_output = gr.Textbox(label="πŸ“Š Sentiment", lines=1)
53
 
54
  with gr.Row():
55
+ analyze_btn = gr.Button("πŸ” Analyze")
56
+ clear_btn = gr.Button("🧹 Clear")
57
 
58
+ analyze_btn.click(analyze_review, inputs=review_input, outputs=[summary_output, sentiment_output])
59
+ clear_btn.click(lambda: ("", "", ""), outputs=[review_input, summary_output, sentiment_output])
60
 
61
+ gr.Examples(examples=examples, inputs=review_input, label="πŸ” Try Example Reviews")
 
62
 
63
+ with gr.Accordion("ℹ️ About this App", open=False):
64
+ gr.Markdown(
65
+ """
66
+ This application uses a fine-tuned T5 model to summarize lengthy product reviews into short summaries and also classifies the sentiment as Positive or Negative.
67
+ - Model: `Manish014/review-summariser-gpt-config1`
68
+ - Summarization by πŸ€— Transformers
69
+ - Sentiment by `distilbert-base-uncased-finetuned-sst-2-english`
70
+ """
71
+ )
72
 
73
+ # Run app
74
  if __name__ == "__main__":
75
  demo.launch()