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()