Added Gradio UI with examples
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Manish014/review-summariser-gpt-config1")
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("Manish014/review-summariser-gpt-config1")
|
7 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
8 |
+
|
9 |
+
# Function to summarize + classify
|
10 |
+
def summarize_and_classify(review):
|
11 |
+
if not review.strip():
|
12 |
+
return "Please enter a review.", "N/A"
|
13 |
+
inputs = tokenizer("summarize: " + review, return_tensors="pt", truncation=True)
|
14 |
+
output_ids = model.generate(inputs["input_ids"], max_length=60, min_length=10, num_beams=4)
|
15 |
+
summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
16 |
+
sentiment = sentiment_pipeline(review)[0]['label']
|
17 |
+
return summary, sentiment
|
18 |
+
|
19 |
+
# Gradio Interface
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=summarize_and_classify,
|
22 |
+
inputs=gr.Textbox(label="📝 Enter a Product Review", lines=4, placeholder="Paste a review here..."),
|
23 |
+
outputs=[
|
24 |
+
gr.Textbox(label="📌 Generated Summary"),
|
25 |
+
gr.Textbox(label="💬 Sentiment")
|
26 |
+
],
|
27 |
+
title="🧠 Review Summariser GPT + Sentiment Classifier",
|
28 |
+
description="Paste a product review to generate a short summary and detect sentiment using a fine-tuned T5 model.",
|
29 |
+
examples=[
|
30 |
+
["This is hands down the best vacuum cleaner I’ve ever owned. It’s lightweight, powerful, and the battery lasts forever!"],
|
31 |
+
["Product arrived broken and late. Extremely disappointed with the quality and packaging."],
|
32 |
+
["Good value for the price. The headphones sound great, but the build feels a bit cheap."]
|
33 |
+
]
|
34 |
+
)
|
35 |
+
|
36 |
+
iface.launch()
|