Benjamin S Liang commited on
Commit
ee38f19
1 Parent(s): 55bdad4

Fixed app.py and added requirements

Browse files
Files changed (2) hide show
  1. app.py.txt → app.py +5 -5
  2. requirements.txt +1 -0
app.py.txt → app.py RENAMED
@@ -2,13 +2,13 @@ import streamlit as st
2
  from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer, TFAutoModelForSequenceClassification, DistillbertForSequenceClassification
3
 
4
  # Options for models from transformers library
5
- MODEL_OPTS = ['default', 'bertweet-base-sentiment-analysis, 'twitter-roberta-base', 'distilRoberta-financial-sentiment']
6
- DEFAULT_OPT = model_opts[0]
7
 
8
  # returns loaded model and tokenizer, if any
9
  def load_model(opt):
10
  if opt not in MODEL_OPTS: print("Incorrect model selection. Try again!")
11
- model, tokenizer = NULL, NULL
12
 
13
  # Load the chosen sentiment analysis model from transformers
14
  if opt == DEFAULT_OPT:
@@ -26,13 +26,13 @@ def load_model(opt):
26
  tokenizer = AutoTokenizer.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")
27
  model = AutoModelForSequenceClassification.from_pretrained("nlptown/bert-base-multilingual-uncas
28
 
29
- elif model is NULL and tokenizer is NULL:
30
  print("Model not loaded correctly. Try again!")
31
 
32
  return model, tokenizer
33
 
34
  def sentiment_analysis(model, tokenizer):
35
- if tokenizer not NULL:
36
  return pipeline('text-classification', model=model, tokenizer=tokenizer)
37
  else: return pipeline('text-classification', model=model)
38
 
 
2
  from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer, TFAutoModelForSequenceClassification, DistillbertForSequenceClassification
3
 
4
  # Options for models from transformers library
5
+ MODEL_OPTS = ['default', 'bertweet-base-sentiment-analysis', 'twitter-roberta-base', 'distilRoberta-financial-sentiment']
6
+ DEFAULT_OPT = MODEL_OPTS[0]
7
 
8
  # returns loaded model and tokenizer, if any
9
  def load_model(opt):
10
  if opt not in MODEL_OPTS: print("Incorrect model selection. Try again!")
11
+ model, tokenizer = None, None
12
 
13
  # Load the chosen sentiment analysis model from transformers
14
  if opt == DEFAULT_OPT:
 
26
  tokenizer = AutoTokenizer.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")
27
  model = AutoModelForSequenceClassification.from_pretrained("nlptown/bert-base-multilingual-uncas
28
 
29
+ elif not model and not tokenizer:
30
  print("Model not loaded correctly. Try again!")
31
 
32
  return model, tokenizer
33
 
34
  def sentiment_analysis(model, tokenizer):
35
+ if tokenizer:
36
  return pipeline('text-classification', model=model, tokenizer=tokenizer)
37
  else: return pipeline('text-classification', model=model)
38
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit