import gradio as gr from transformers import pipeline # Load the sentiment analysis model model_name = "AventIQ-AI/bert-movie-review-sentiment-analysis" sentiment_analyzer = pipeline("sentiment-analysis", model=model_name) # Mapping labels (Adjust based on actual model output) label_mapping = { "LABEL_0": "Negative", "LABEL_1": "Positive" } def analyze_sentiment(review_text): """Analyzes the sentiment of a given movie review.""" if not review_text.strip(): return "⚠️ Please enter a movie review." result = sentiment_analyzer(review_text)[0] label = label_mapping.get(result['label'], result['label']) # Convert label confidence = round(result['score'] * 100, 2) emoji = "😃" if label == "Positive" else "😞" return f"{emoji} Sentiment: **{label}** (Confidence: {confidence}%)" # Example movie reviews example_reviews = [ "This movie was absolutely fantastic! The story was gripping, and the acting was top-notch.", "I was really disappointed. The plot was dull, and the characters were not relatable at all.", "An entertaining experience with great visuals and a compelling story!", "One of the worst movies I've ever seen. Total waste of time." ] # Create Gradio UI with gr.Blocks() as demo: gr.Markdown("## 🎬 Movie Review Sentiment Analysis") gr.Markdown("Enter a movie review, and the AI will determine if the sentiment is **positive** or **negative**!") with gr.Row(): input_text = gr.Textbox(label="✍️ Enter your movie review:", placeholder="Example: 'The movie was thrilling with an amazing plot twist!'") analyze_button = gr.Button("🔍 Analyze Sentiment") output_text = gr.Textbox(label="🎭 Sentiment Result:") gr.Markdown("### 🎥 Example Reviews") example_buttons = [gr.Button(example) for example in example_reviews] for btn in example_buttons: btn.click(fn=lambda text=btn.value: text, outputs=input_text) analyze_button.click(analyze_sentiment, inputs=input_text, outputs=output_text) # Launch the Gradio app demo.launch()