Manish014's picture
new updates
b723159 verified
import gradio as gr
from transformers import pipeline
# Load models
summarizer = pipeline(
"summarization",
model="Manish014/review-summariser-gpt-config1",
tokenizer="Manish014/review-summariser-gpt-config1",
device=0 # Use GPU if available
)
sentiment_analyzer = pipeline("sentiment-analysis")
# Inference function
def analyze_review(text):
if not text.strip():
return "❗ Please enter a product review.", "❗ Sentiment unavailable."
summary = summarizer(
text,
max_length=80,
min_length=10,
num_beams=4,
early_stopping=True,
length_penalty=1.2
)[0]["summary_text"]
sentiment = sentiment_analyzer(text)[0]
sentiment_label = f"{sentiment['label']} ({round(sentiment['score'] * 100, 2)}%)"
return summary, sentiment_label
# Example inputs
examples = [
["This product leaks water and smells like burnt plastic."],
["Absolutely loved the screen resolution and battery life."],
["Worst purchase I've made. Do not recommend at all."],
["The headphones are okay. Battery is good but fit is not comfortable."],
["The fan is extremely loud and doesn't cool much."]
]
# Build UI
with gr.Blocks(theme=gr.themes.Base()) as demo:
gr.Markdown("## πŸ“ Review Summariser GPT - Config 1")
gr.Markdown("Enter a detailed product review below to receive a helpful summary βœ‚οΈ and predicted sentiment πŸ“Š.")
with gr.Row():
review_input = gr.Textbox(label="πŸ—£οΈ Product Review", lines=5, placeholder="Write your review here...")
with gr.Row():
summary_output = gr.Textbox(label="βœ‚οΈ Summary", lines=2)
sentiment_output = gr.Textbox(label="πŸ“Š Sentiment", lines=1)
with gr.Row():
analyze_btn = gr.Button("πŸ” Analyze")
clear_btn = gr.Button("🧹 Clear")
analyze_btn.click(analyze_review, inputs=review_input, outputs=[summary_output, sentiment_output])
clear_btn.click(lambda: ("", "", ""), outputs=[review_input, summary_output, sentiment_output])
gr.Examples(examples=examples, inputs=review_input, label="πŸ” Try Example Reviews")
with gr.Accordion("ℹ️ About this App", open=False):
gr.Markdown(
"""
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.
- Model: `Manish014/review-summariser-gpt-config1`
- Summarization by πŸ€— Transformers
- Sentiment by `distilbert-base-uncased-finetuned-sst-2-english`
"""
)
# Run app
if __name__ == "__main__":
demo.launch()