Spaces:
Running
Running
Added Model and spinner
Browse files
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 |
-
"
|
|
|
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", "
|
36 |
# Add models parameters
|
37 |
st.header("Models")
|
38 |
settings["model"] = st.selectbox("Select Model", models)
|
39 |
|
40 |
|
41 |
if st.button("Search"):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
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))
|