Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load the pre-trained model (using the
|
5 |
def load_model():
|
6 |
-
# Use
|
7 |
return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
|
8 |
|
9 |
# Initialize the model
|
@@ -11,8 +11,14 @@ sentiment_model = load_model()
|
|
11 |
|
12 |
# Function to analyze sentiment and provide motivational feedback
|
13 |
def analyze_sentiment(user_input):
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Analyze the mood and provide motivational messages accordingly
|
18 |
if sentiment == 'negative':
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the pre-trained model (using the provided model or custom trained model)
|
5 |
def load_model():
|
6 |
+
# Use Hugging Face's 'cardiffnlp/twitter-roberta-base-sentiment' or a custom model path
|
7 |
return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
|
8 |
|
9 |
# Initialize the model
|
|
|
11 |
|
12 |
# Function to analyze sentiment and provide motivational feedback
|
13 |
def analyze_sentiment(user_input):
|
14 |
+
# Get sentiment prediction
|
15 |
+
result = sentiment_model(user_input)
|
16 |
+
|
17 |
+
if not result:
|
18 |
+
return "Could not determine sentiment. Please try again."
|
19 |
+
|
20 |
+
sentiment = result[0]['label'].lower() # Extract sentiment label and convert to lowercase for comparison
|
21 |
+
print(f"Sentiment Analysis Result: {result}") # Debug: Print model result for review
|
22 |
|
23 |
# Analyze the mood and provide motivational messages accordingly
|
24 |
if sentiment == 'negative':
|