Sasidhar commited on
Commit
0d3f45a
1 Parent(s): 8eb040b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -4,13 +4,7 @@ import streamlit as st
4
  from transformers import AutoTokenizer, AutoModelWithLMHead
5
  from transformers import pipeline
6
 
7
- #tokenizer = AutoTokenizer.from_pretrained("gpt2-medium")
8
  sentiment_tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-imdb-sentiment")
9
-
10
- @st.cache
11
- def load_model(model_name):
12
- model = AutoModelWithLMHead.from_pretrained(model_name)
13
- return model
14
 
15
  def load_text_gen_model():
16
  generator = pipeline("text-generation", model="gpt2-medium")
@@ -20,18 +14,19 @@ def load_text_gen_model():
20
  def get_sentiment_model():
21
  sentiment_model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-imdb-sentiment")
22
  return sentiment_model
23
-
 
 
 
 
 
24
  def get_sentiment(text):
25
  input_ids = sentiment_tokenizer .encode(text + '</s>', return_tensors='pt')
26
- output = sentiment_model.generate(input_ids=input_ids,max_length=2)
27
  dec = [sentiment_tokenizer.decode(ids) for ids in output]
28
  label = dec[0]
29
  return label
30
 
31
- #@st.cache(allow_output_mutation=True)
32
- def get_summarizer():
33
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
34
- return summarizer
35
 
36
  def get_qa_model():
37
  model_name = "deepset/roberta-base-squad2"
@@ -39,11 +34,9 @@ def get_qa_model():
39
  qa_pipeline = pipeline('question-answering', model=model_name, tokenizer=model_name)
40
  return qa_pipeline
41
 
42
- sentiment_model = get_sentiment_model()
43
- summarizer = get_summarizer()
44
- answer_geerator = get_qa_model()
45
-
46
- #text_generator = load_text_gen_model()
47
 
48
  action = st.sidebar.selectbox("Pick an Action", ["Analyse a Review","Generate an Article","Create an Image"])
49
 
@@ -63,7 +56,7 @@ if action == "Analyse a Review":
63
  if st.button("Find the key topic"):
64
  QA_input = {'question': 'what is the review about?',
65
  'context': review}
66
- answer = answer_geerator (QA_input)
67
  st.write(answer)
68
 
69
 
 
4
  from transformers import AutoTokenizer, AutoModelWithLMHead
5
  from transformers import pipeline
6
 
 
7
  sentiment_tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-imdb-sentiment")
 
 
 
 
 
8
 
9
  def load_text_gen_model():
10
  generator = pipeline("text-generation", model="gpt2-medium")
 
14
  def get_sentiment_model():
15
  sentiment_model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-imdb-sentiment")
16
  return sentiment_model
17
+
18
+ def get_summarizer_model():
19
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
20
+ return summarizer
21
+
22
+
23
  def get_sentiment(text):
24
  input_ids = sentiment_tokenizer .encode(text + '</s>', return_tensors='pt')
25
+ output = sentiment_extractor.generate(input_ids=input_ids,max_length=2)
26
  dec = [sentiment_tokenizer.decode(ids) for ids in output]
27
  label = dec[0]
28
  return label
29
 
 
 
 
 
30
 
31
  def get_qa_model():
32
  model_name = "deepset/roberta-base-squad2"
 
34
  qa_pipeline = pipeline('question-answering', model=model_name, tokenizer=model_name)
35
  return qa_pipeline
36
 
37
+ sentiment_extractor = get_sentiment_model()
38
+ summarizer = get_summarizer_model()
39
+ answer_generator = get_qa_model()
 
 
40
 
41
  action = st.sidebar.selectbox("Pick an Action", ["Analyse a Review","Generate an Article","Create an Image"])
42
 
 
56
  if st.button("Find the key topic"):
57
  QA_input = {'question': 'what is the review about?',
58
  'context': review}
59
+ answer = answer_generator(QA_input)
60
  st.write(answer)
61
 
62