Roozeec commited on
Commit
0ded43b
1 Parent(s): 6323541

Added Model and spinner

Browse files
Files changed (1) hide show
  1. app.py +34 -30
app.py CHANGED
@@ -11,7 +11,8 @@ st.subheader("Search for News and classify the headlines with sentiment analysis
11
  query = st.text_input("Enter Query")
12
 
13
  models = [
14
- "SamLowe/roberta-base-go_emotions",
 
15
  # "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
16
  ]
17
 
@@ -32,41 +33,44 @@ with st.sidebar:
32
 
33
  # add period parameter
34
  st.header("Period")
35
- settings["period"] = st.selectbox("Select Period", ["1d", "7", "30d"])
36
  # Add models parameters
37
  st.header("Models")
38
  settings["model"] = st.selectbox("Select Model", models)
39
 
40
 
41
  if st.button("Search"):
42
- classifier = pipeline(task="text-classification", model=settings["model"], top_k=None)
43
- df = wna.get_news(settings, query)
44
- # st.dataframe(df)
45
- # get each title colums
46
- sentences = df["title"]
47
- # convert into array
48
- sentences = sentences.tolist()
49
- # st.write(sentences)
50
- # create new dataframe
51
- df = pd.DataFrame(columns=["sentence", "best","second"])
52
- # loop on each sentence and call classifier
53
- for sentence in sentences:
54
- cur_sentence = sentence
55
- model_outputs = classifier(sentence)
56
- cur_result = model_outputs[0]
57
- #st.write(cur_result)
58
- # get label 1
59
- label = cur_result[0]['label']
60
- score = cur_result[0]['score']
61
- percentage = round(score * 100, 2)
62
- str1 = label + " " + str(percentage)
63
- # get label 2
64
- label = cur_result[1]['label']
65
- score = cur_result[1]['score']
66
- percentage = round(score * 100, 2)
67
- str2 = label + " " + str(percentage)
68
- # insert cur_sentence and cur_result into dataframe
69
- df.loc[len(df.index)] = [cur_sentence, str1, str2]
 
 
 
70
 
71
  # write info on the output
72
  st.write("Number of sentences:", len(df))
 
11
  query = st.text_input("Enter Query")
12
 
13
  models = [
14
+ "j-hartmann/emotion-english-distilroberta-base",
15
+ "SamLowe/roberta-base-go_emotions"
16
  # "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
17
  ]
18
 
 
33
 
34
  # add period parameter
35
  st.header("Period")
36
+ settings["period"] = st.selectbox("Select Period", ["1d", "7d", "30d"])
37
  # Add models parameters
38
  st.header("Models")
39
  settings["model"] = st.selectbox("Select Model", models)
40
 
41
 
42
  if st.button("Search"):
43
+ # display a loading progress
44
+ with st.spinner("Loading last news ..."):
45
+ classifier = pipeline(task="text-classification", model=settings["model"], top_k=None)
46
+ df = wna.get_news(settings, query)
47
+ with st.spinner("Processing received news ..."):
48
+ # st.dataframe(df)
49
+ # get each title colums
50
+ sentences = df["title"]
51
+ # convert into array
52
+ sentences = sentences.tolist()
53
+ # st.write(sentences)
54
+ # create new dataframe
55
+ df = pd.DataFrame(columns=["sentence", "best","second"])
56
+ # loop on each sentence and call classifier
57
+ for sentence in sentences:
58
+ cur_sentence = sentence
59
+ model_outputs = classifier(sentence)
60
+ cur_result = model_outputs[0]
61
+ #st.write(cur_result)
62
+ # get label 1
63
+ label = cur_result[0]['label']
64
+ score = cur_result[0]['score']
65
+ percentage = round(score * 100, 2)
66
+ str1 = label + " " + str(percentage)
67
+ # get label 2
68
+ label = cur_result[1]['label']
69
+ score = cur_result[1]['score']
70
+ percentage = round(score * 100, 2)
71
+ str2 = label + " " + str(percentage)
72
+ # insert cur_sentence and cur_result into dataframe
73
+ df.loc[len(df.index)] = [cur_sentence, str1, str2]
74
 
75
  # write info on the output
76
  st.write("Number of sentences:", len(df))