Roozeec commited on
Commit
4b7389c
1 Parent(s): 222dd14

updated code

Browse files
Files changed (1) hide show
  1. app.py +44 -8
app.py CHANGED
@@ -1,24 +1,36 @@
1
  import streamlit as st
2
  import wna_googlenews as wna
 
3
  from transformers import pipeline
4
 
 
5
 
6
  st.title("WNA Google News App")
7
- st.subheader("Search for News")
8
-
9
- # create a dropdown menu for selecting days range
10
- days_range = st.selectbox("Select Days Range", ["1d", "7", "30d"])
11
 
12
  query = st.text_input("Enter Query")
13
 
14
  settings = {
15
  "lang": "fr",
16
  "region": "FR",
17
- "period": days_range
18
  }
19
 
20
  classifier = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None)
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  if st.button("Search"):
24
  df = wna.get_news(settings, query)
@@ -27,7 +39,31 @@ if st.button("Search"):
27
  sentences = df["title"]
28
  # convert into array
29
  sentences = sentences.tolist()
30
- st.write(sentences)
31
- model_outputs = classifier(sentences)
32
- st.write(model_outputs[0])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
 
1
  import streamlit as st
2
  import wna_googlenews as wna
3
+ import pandas as pd
4
  from transformers import pipeline
5
 
6
+ st.set_page_config(layout="wide")
7
 
8
  st.title("WNA Google News App")
9
+ st.subheader("Search for News and classify the headlines with sentiment analysis")
 
 
 
10
 
11
  query = st.text_input("Enter Query")
12
 
13
  settings = {
14
  "lang": "fr",
15
  "region": "FR",
16
+ "period": "1d"
17
  }
18
 
19
  classifier = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None)
20
 
21
+ with st.sidebar:
22
+ st.title("Settings")
23
+ # add language and country parameters
24
+ st.header("Language and Country")
25
+ settings["lang"] = st.selectbox("Select Language", ["en", "fr"])
26
+ settings["region"] = st.selectbox("Select Country", ["US", "FR"])
27
+
28
+ # add period parameter
29
+ st.header("Period")
30
+ settings["period"] = st.selectbox("Select Period", ["1d", "7", "30d"])
31
+
32
+
33
+
34
 
35
  if st.button("Search"):
36
  df = wna.get_news(settings, query)
 
39
  sentences = df["title"]
40
  # convert into array
41
  sentences = sentences.tolist()
42
+ # st.write(sentences)
43
+ # create new dataframe
44
+ df = pd.DataFrame(columns=["sentence", "best","second"])
45
+ # loop on each sentence and call classifier
46
+ for sentence in sentences:
47
+ cur_sentence = sentence
48
+ model_outputs = classifier(sentence)
49
+ cur_result = model_outputs[0]
50
+ #st.write(cur_result)
51
+ # get label 1
52
+ label = cur_result[0]['label']
53
+ score = cur_result[0]['score']
54
+ percentage = round(score * 100, 2)
55
+ str1 = label + " " + str(percentage)
56
+ # get label 2
57
+ label = cur_result[1]['label']
58
+ score = cur_result[1]['score']
59
+ percentage = round(score * 100, 2)
60
+ str2 = label + " " + str(percentage)
61
+ # insert cur_sentence and cur_result into dataframe
62
+ df.loc[len(df.index)] = [cur_sentence, str1, str2]
63
+
64
+ # write info on the output
65
+ st.write("Number of sentences:", len(df))
66
+ st.write("Language:", settings["lang"], "Country:", settings["region"])
67
+
68
+ st.dataframe(df)
69