Spaces:
Runtime error
Runtime error
File size: 2,902 Bytes
4bdbc0f ba14486 4bdbc0f ba14486 4bdbc0f ba14486 9f86725 ba14486 09371d6 ba14486 bde276c de7b0d5 bde276c 1fd7793 ec3da70 4bdbc0f de7b0d5 ba14486 ab3f219 ba14486 8638c6d ba14486 9f86725 ba14486 9f86725 ba14486 89bfa76 7975f60 8e61a24 f98fca8 e21bfa3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
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")
list_of_dictionaries = []
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:
dataframe = pd.read_csv(uploaded_file)
# Continue with your Streamlit app logic, e.g., displaying the DataFrame
st.write(dataframe)
# rest of your code to process the dataframe
else:
# You can choose to write an error message or just do nothing
st.write("Please upload a CSV file to proceed.")
if st.button("Classify"):
# Perform text classification on the input text
for n in range(len(dataframe)):
results = classifier(dataframe['content'].iloc[n])[0]
# 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']
new_dictionary = {
"Text":dataframe['content'].iloc[n],
"Label" : max_label
}
list_of_dictionaries.append(new_dictionary)
filtered_list = [d for d in list_of_dictionaries if d['Label'].strip() == select]
st.write(len(filtered_list))
for m in range(len(filtered_list)):
summarize = summarizer(filtered_list[m]['Text'])[0]
st.write(f"Summary No.{m}:", summarize)
|