Spaces:
Running
Running
Muhammad Haris
commited on
Commit
•
18f90dd
1
Parent(s):
081d2b5
Update app.py
Browse files
app.py
CHANGED
@@ -11,72 +11,52 @@ st.subheader("Search for News and classify the headlines with sentiment analysis
|
|
11 |
query = st.text_input("Enter Query")
|
12 |
|
13 |
models = [
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
]
|
18 |
|
19 |
settings = {
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
"number_of_pages": 5
|
24 |
}
|
25 |
|
26 |
-
|
27 |
with st.sidebar:
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# settings["langregion"] = st.selectbox("Select Language", ["en/US", "fr/FR"])
|
33 |
-
# input field for number of pages
|
34 |
-
st.header("Number of Pages")
|
35 |
-
settings["number_of_pages"] = st.number_input("Enter Number of Pages", min_value=1, max_value=10)
|
36 |
-
|
37 |
-
# settings["region"] = settings["langregion"].split("/")[0]
|
38 |
-
# settings["lang"] = settings["langregion"].split("/")[1]
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
settings["period"] = st.selectbox("Select Period", ["1d", "7d", "30d"])
|
43 |
-
# Add models parameters
|
44 |
-
st.header("Models")
|
45 |
-
settings["model"] = st.selectbox("Select Model", models)
|
46 |
|
|
|
|
|
47 |
|
48 |
if st.button("Search"):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
percentage = round(score * 100, 2)
|
68 |
-
str1 = label + " (" + str(percentage) + ")%"
|
69 |
-
# get label 2
|
70 |
-
label = cur_result[1]['label']
|
71 |
-
score = cur_result[1]['score']
|
72 |
-
percentage = round(score * 100, 2)
|
73 |
-
str2 = label + " (" + str(percentage) + ")%"
|
74 |
-
# insert cur_sentence and cur_result into dataframe
|
75 |
-
df.loc[len(df.index)] = [cur_sentence, cur_date, str1, str2]
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
|
82 |
|
|
|
|
|
|
11 |
query = st.text_input("Enter Query")
|
12 |
|
13 |
models = [
|
14 |
+
"j-hartmann/emotion-english-distilroberta-base",
|
15 |
+
"SamLowe/roberta-base-go_emotions"
|
16 |
+
]
|
|
|
17 |
|
18 |
settings = {
|
19 |
+
"period": "1d",
|
20 |
+
"model": models[0],
|
21 |
+
"number_of_pages": 5
|
|
|
22 |
}
|
23 |
|
|
|
24 |
with st.sidebar:
|
25 |
+
st.title("Settings")
|
26 |
+
st.header("Number of Pages")
|
27 |
+
settings["number_of_pages"] = st.number_input("Enter Number of Pages", min_value=1, max_value=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
st.header("Period")
|
30 |
+
settings["period"] = st.selectbox("Select Period", ["1d", "7d", "30d"])
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
st.header("Models")
|
33 |
+
settings["model"] = st.selectbox("Select Model", models)
|
34 |
|
35 |
if st.button("Search"):
|
36 |
+
classifier = pipeline(task="text-classification", model=settings["model"], top_k=None)
|
37 |
+
|
38 |
+
with st.spinner("Loading last news ..."):
|
39 |
+
allnews = wna.get_news(settings, query)
|
40 |
+
st.dataframe(allnews)
|
41 |
+
|
42 |
+
with st.spinner("Processing received news ..."):
|
43 |
+
df = pd.DataFrame(columns=["sentence", "date", "best", "second"])
|
44 |
+
|
45 |
+
for curnews in allnews:
|
46 |
+
cur_sentence = curnews["title"]
|
47 |
+
cur_date = curnews["date"]
|
48 |
+
model_outputs = classifier(cur_sentence)
|
49 |
+
cur_result = model_outputs[0]
|
50 |
+
|
51 |
+
label1 = cur_result[0]['label']
|
52 |
+
score1 = round(cur_result[0]['score'] * 100, 2)
|
53 |
+
str1 = f"{label1} ({score1}%)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
label2 = cur_result[1]['label']
|
56 |
+
score2 = round(cur_result[1]['score'] * 100, 2)
|
57 |
+
str2 = f"{label2} ({score2}%)"
|
58 |
|
59 |
+
df.loc[len(df.index)] = [cur_sentence, cur_date, str1, str2]
|
60 |
|
61 |
+
st.write("Number of sentences:", len(df))
|
62 |
+
st.dataframe(df)
|