Madiharehan commited on
Commit
e9f4ddd
·
verified ·
1 Parent(s): 025ebfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
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 trained model you provided)
5
  def load_model():
6
- # Use your trained model here; if it's hosted on Hugging Face, provide the path or URL to the model
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
- result = sentiment_model(user_input)[0]
15
- sentiment = result['label'].lower() # Convert to lowercase for easier comparison
 
 
 
 
 
 
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':