Spaces:
Runtime error
Runtime error
Commit
•
ba14486
1
Parent(s):
f7762fc
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,107 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load the text classification model pipeline
|
5 |
classifier = pipeline("text-classification", model="cychristophercyc/Group12_CustomModel_victory", return_all_scores=True)
|
|
|
6 |
|
7 |
# Streamlit application title
|
8 |
-
st.title("
|
9 |
-
st.write("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
text = st.text_area("Enter the text to classify", "")
|
12 |
-
# Perform text classification when the user clicks the "Classify" button
|
13 |
if st.button("Classify"):
|
14 |
# Perform text classification on the input text
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from io import StringIO
|
4 |
+
import csv
|
5 |
from transformers import pipeline
|
6 |
|
7 |
# Load the text classification model pipeline
|
8 |
classifier = pipeline("text-classification", model="cychristophercyc/Group12_CustomModel_victory", return_all_scores=True)
|
9 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
|
11 |
# Streamlit application title
|
12 |
+
st.title("News Categorization")
|
13 |
+
st.write("Upload a CVS file containing content in 'content' column")
|
14 |
+
|
15 |
+
|
16 |
+
genre = st.radio(
|
17 |
+
"What's your Chosen Category",
|
18 |
+
[":rainbow[Business and Finance]",
|
19 |
+
":rainbow[Health and Wellness]",
|
20 |
+
":rainbow[Sports]",
|
21 |
+
":rainbow[Arts, Culture, and Entertainment]",
|
22 |
+
":rainbow[Politics]",
|
23 |
+
":rainbow[Science and Technology]",
|
24 |
+
],
|
25 |
+
)
|
26 |
+
|
27 |
+
if genre == ':rainbow[Business and Finance]':
|
28 |
+
st.write('You selected Business and Finance.')
|
29 |
+
select = "Business and Finance"
|
30 |
+
|
31 |
+
if genre == ':rainbow[Health and Wellness]':
|
32 |
+
st.write('You selected Health and Wellness.')
|
33 |
+
select = "Health and Wellness"
|
34 |
+
|
35 |
+
if genre == ':rainbow[Sports]':
|
36 |
+
st.write('You selected Sports.')
|
37 |
+
select = "Sports"
|
38 |
+
|
39 |
+
if genre == ':rainbow[Arts, Culture, and Entertainment]':
|
40 |
+
st.write('You selected Arts, Culture, and Entertainment.')
|
41 |
+
select = "Arts, Culture, and Entertainment"
|
42 |
+
|
43 |
+
if genre == ':rainbow[Politics]':
|
44 |
+
st.write('You selected Politics.')
|
45 |
+
select = "Politics"
|
46 |
+
|
47 |
+
if genre == ':rainbow[Science and Technology]':
|
48 |
+
st.write('You selected Science and Technology.')
|
49 |
+
select = "Science and Technology"
|
50 |
+
|
51 |
+
|
52 |
+
# upload file
|
53 |
+
uploaded_file = st.file_uploader("Choose a file")
|
54 |
+
if uploaded_file is not None:
|
55 |
+
|
56 |
+
# To read file as bytes:
|
57 |
+
bytes_data = uploaded_file.getvalue()
|
58 |
+
st.write(bytes_data)
|
59 |
+
|
60 |
+
# To convert to a string based IO:
|
61 |
+
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
62 |
+
st.write(stringio)
|
63 |
+
|
64 |
+
# To read file as string:
|
65 |
+
string_data = stringio.read()
|
66 |
+
st.write(string_data)
|
67 |
+
|
68 |
+
# Can be used wherever a "file-like" object is accepted:
|
69 |
+
dataframe = pd.read_csv(uploaded_file)
|
70 |
+
st.write(dataframe)
|
71 |
+
|
72 |
+
a = 0
|
73 |
+
content_list = []
|
74 |
+
list_of_dictionaries =[]
|
75 |
+
for row in dataframe:
|
76 |
+
# Extract the 'content' element and add it to the content_list
|
77 |
+
content_list.append(row['content'])
|
78 |
+
a+=1
|
79 |
+
|
80 |
|
|
|
|
|
81 |
if st.button("Classify"):
|
82 |
# Perform text classification on the input text
|
83 |
+
for n in range(a):
|
84 |
+
results = classifier(content_list)[n]
|
85 |
+
# Display the classification result
|
86 |
+
max_score = float('-inf')
|
87 |
+
max_label = ''
|
88 |
+
for result in results:
|
89 |
+
if result['score'] > max_score:
|
90 |
+
max_score = result['score']
|
91 |
+
max_label = result['label']
|
92 |
+
st.write("Text:", content_list[n])
|
93 |
+
st.write("Label:", max_label)
|
94 |
+
st.write("Score:", max_score)
|
95 |
+
new_dictionary = {
|
96 |
+
"Text":content_list[n],
|
97 |
+
"Label" : max_label
|
98 |
+
}
|
99 |
+
list_of_dictionaries.append(new_dictionary)
|
100 |
+
|
101 |
+
|
102 |
+
filtered_list = [d for d in list_of_dictionaries if d['Label'].strip() == select]
|
103 |
+
|
104 |
+
|
105 |
+
for m in len(filtered_list):
|
106 |
+
Sum = summarizer(content_list)[m]
|
107 |
+
st.write("Summary:", content_list)[m])
|