Hwilner commited on
Commit
ad1f13f
·
verified ·
1 Parent(s): 789220a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -0
app.py CHANGED
@@ -4,6 +4,7 @@ import pandas as pd
4
  import matplotlib.pyplot as plt
5
  from transformers import pipeline
6
 
 
7
  model_name = "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
8
  analyzer = pipeline("text-classification", model=model_name)
9
 
@@ -12,6 +13,7 @@ def sentiment_analyzer(review):
12
  sentiment = analyzer(review)
13
  return sentiment[0]['label']
14
  except Exception as e:
 
15
  return f"Error: {e}"
16
 
17
  def sentiment_bar_chart(df):
@@ -32,6 +34,7 @@ def read_reviews_and_analyze_sentiment(file_object):
32
  chart_object = sentiment_bar_chart(df)
33
  return df, chart_object
34
  except Exception as e:
 
35
  return f"Error: {e}", None
36
 
37
  gr.close_all()
 
4
  import matplotlib.pyplot as plt
5
  from transformers import pipeline
6
 
7
+ # Use a pipeline with a suitable model for sentiment analysis
8
  model_name = "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
9
  analyzer = pipeline("text-classification", model=model_name)
10
 
 
13
  sentiment = analyzer(review)
14
  return sentiment[0]['label']
15
  except Exception as e:
16
+ print(f"Error in sentiment_analyzer: {e}")
17
  return f"Error: {e}"
18
 
19
  def sentiment_bar_chart(df):
 
34
  chart_object = sentiment_bar_chart(df)
35
  return df, chart_object
36
  except Exception as e:
37
+ print(f"Error in read_reviews_and_analyze_sentiment: {e}")
38
  return f"Error: {e}", None
39
 
40
  gr.close_all()