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