ayushsinha commited on
Commit
ba92ce2
Β·
verified Β·
1 Parent(s): 956c8bc

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +55 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis model
5
+ model_name = "AventIQ-AI/bert-movie-review-sentiment-analysis"
6
+ sentiment_analyzer = pipeline("sentiment-analysis", model=model_name)
7
+
8
+ # Mapping labels (Adjust based on actual model output)
9
+ label_mapping = {
10
+ "LABEL_0": "Negative",
11
+ "LABEL_1": "Positive"
12
+ }
13
+
14
+ def analyze_sentiment(review_text):
15
+ """Analyzes the sentiment of a given movie review."""
16
+ if not review_text.strip():
17
+ return "⚠️ Please enter a movie review."
18
+
19
+ result = sentiment_analyzer(review_text)[0]
20
+ label = label_mapping.get(result['label'], result['label']) # Convert label
21
+ confidence = round(result['score'] * 100, 2)
22
+
23
+ emoji = "πŸ˜ƒ" if label == "Positive" else "😞"
24
+ return f"{emoji} Sentiment: **{label}** (Confidence: {confidence}%)"
25
+
26
+ # Example movie reviews
27
+ example_reviews = [
28
+ "This movie was absolutely fantastic! The story was gripping, and the acting was top-notch.",
29
+ "I was really disappointed. The plot was dull, and the characters were not relatable at all.",
30
+ "An entertaining experience with great visuals and a compelling story!",
31
+ "One of the worst movies I've ever seen. Total waste of time."
32
+ ]
33
+
34
+ # Create Gradio UI
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("## 🎬 Movie Review Sentiment Analysis")
37
+ gr.Markdown("Enter a movie review, and the AI will determine if the sentiment is **positive** or **negative**!")
38
+
39
+ with gr.Row():
40
+ input_text = gr.Textbox(label="✍️ Enter your movie review:",
41
+ placeholder="Example: 'The movie was thrilling with an amazing plot twist!'")
42
+
43
+ analyze_button = gr.Button("πŸ” Analyze Sentiment")
44
+ output_text = gr.Textbox(label="🎭 Sentiment Result:")
45
+
46
+ gr.Markdown("### πŸŽ₯ Example Reviews")
47
+ example_buttons = [gr.Button(example) for example in example_reviews]
48
+
49
+ for btn in example_buttons:
50
+ btn.click(fn=lambda text=btn.value: text, outputs=input_text)
51
+
52
+ analyze_button.click(analyze_sentiment, inputs=input_text, outputs=output_text)
53
+
54
+ # Launch the Gradio app
55
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio
4
+ sentencepiece
5
+ torchvision
6
+ huggingface_hub
7
+ pillow
8
+ numpy