cychristophercyc's picture
Update app.py
ba14486 verified
raw
history blame
3.19 kB
import streamlit as st
import pandas as pd
from io import StringIO
import csv
from transformers import pipeline
# Load the text classification model pipeline
classifier = pipeline("text-classification", model="cychristophercyc/Group12_CustomModel_victory", return_all_scores=True)
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Streamlit application title
st.title("News Categorization")
st.write("Upload a CVS file containing content in 'content' column")
genre = st.radio(
"What's your Chosen Category",
[":rainbow[Business and Finance]",
":rainbow[Health and Wellness]",
":rainbow[Sports]",
":rainbow[Arts, Culture, and Entertainment]",
":rainbow[Politics]",
":rainbow[Science and Technology]",
],
)
if genre == ':rainbow[Business and Finance]':
st.write('You selected Business and Finance.')
select = "Business and Finance"
if genre == ':rainbow[Health and Wellness]':
st.write('You selected Health and Wellness.')
select = "Health and Wellness"
if genre == ':rainbow[Sports]':
st.write('You selected Sports.')
select = "Sports"
if genre == ':rainbow[Arts, Culture, and Entertainment]':
st.write('You selected Arts, Culture, and Entertainment.')
select = "Arts, Culture, and Entertainment"
if genre == ':rainbow[Politics]':
st.write('You selected Politics.')
select = "Politics"
if genre == ':rainbow[Science and Technology]':
st.write('You selected Science and Technology.')
select = "Science and Technology"
# upload file
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# To read file as bytes:
bytes_data = uploaded_file.getvalue()
st.write(bytes_data)
# To convert to a string based IO:
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
st.write(stringio)
# To read file as string:
string_data = stringio.read()
st.write(string_data)
# Can be used wherever a "file-like" object is accepted:
dataframe = pd.read_csv(uploaded_file)
st.write(dataframe)
a = 0
content_list = []
list_of_dictionaries =[]
for row in dataframe:
# Extract the 'content' element and add it to the content_list
content_list.append(row['content'])
a+=1
if st.button("Classify"):
# Perform text classification on the input text
for n in range(a):
results = classifier(content_list)[n]
# Display the classification result
max_score = float('-inf')
max_label = ''
for result in results:
if result['score'] > max_score:
max_score = result['score']
max_label = result['label']
st.write("Text:", content_list[n])
st.write("Label:", max_label)
st.write("Score:", max_score)
new_dictionary = {
"Text":content_list[n],
"Label" : max_label
}
list_of_dictionaries.append(new_dictionary)
filtered_list = [d for d in list_of_dictionaries if d['Label'].strip() == select]
for m in len(filtered_list):
Sum = summarizer(content_list)[m]
st.write("Summary:", content_list)[m])