Manish014 commited on
Commit
2bfcd91
·
verified ·
1 Parent(s): 6d9ad90
Files changed (1) hide show
  1. app.py +15 -23
app.py CHANGED
@@ -1,34 +1,26 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
 
4
- # Load model
5
- model_name = "Manish014/review-summariser-gpt-config1"
6
- tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
 
9
- summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
10
-
11
- # Define Gradio UI
12
- def summarize_review(review):
13
- if not review.strip():
14
  return "Please enter a review."
15
- output = summarizer(review, max_length=60, min_length=10, do_sample=False)
16
- return output[0]["summary_text"]
17
 
18
- examples = [
19
- ["This is the worst coffee maker I’ve ever used. It leaks water everywhere, the buttons barely work, and the brew tastes like plastic."],
20
- ["Great product! Easy to use, super fast delivery, and the quality is outstanding. Highly recommend!"],
21
- ["Battery life is average but display quality and sound are top-notch."],
22
- ["Not worth the money. Poor customer service and the build feels cheap."]
23
  ]
24
 
25
  demo = gr.Interface(
26
- fn=summarize_review,
27
- inputs=gr.Textbox(lines=6, placeholder="Paste a product review here..."),
28
- outputs="text",
29
- examples=examples,
30
- title="Review Summariser GPT",
31
- description="Enter a product review to get a helpful summary using Config1 fine-tuned T5-small model."
32
  )
33
 
34
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ pipe = pipeline("summarization", model="Manish014/review-summariser-gpt-config1")
 
 
 
5
 
6
+ def summarize(text):
7
+ if not text.strip():
 
 
 
8
  return "Please enter a review."
9
+ return pipe(text)[0]["summary_text"]
 
10
 
11
+ example_reviews = [
12
+ ["This product leaks water and smells like burnt plastic."],
13
+ ["Absolutely loved the screen resolution and battery life."],
14
+ ["Worst purchase I've made. Do not recommend at all."]
 
15
  ]
16
 
17
  demo = gr.Interface(
18
+ fn=summarize,
19
+ inputs=gr.Textbox(lines=5, placeholder="Enter product review..."),
20
+ outputs=gr.Textbox(label="Summary"),
21
+ examples=example_reviews,
22
+ title="Review Summariser GPT - Config 1",
23
+ description="Enter a long product review and get a helpful short summary."
24
  )
25
 
26
  demo.launch()