Text_Analytics_Group / streamlit_app.py
SuchithTissera's picture
Update streamlit_app.py
b290553 verified
Raw History Blame Contribute Delete
3.43 kB
#importing all the libraries needed for basic classification and presentation of cover page
import streamlit as st
from transformers import pipeline
#adding the css presentation from the styles file in utils
from utils.styles import load_css
#configure the page to display the intended title
st.set_page_config(
page_title="Daily Mirror News Analyzer",
layout="wide"
)
#calling the css changes
load_css()
#writing the title
st.markdown('<div class="main_title">News App — Created by Group 09</div>',
unsafe_allow_html=True)
#writing the description
st.write('''<div class="feature_text">Welcome! In this app users can freely
carry out classification of news content, ask our model questions and play
our mini-game to see your classification skills </div> <br>''',unsafe_allow_html=True)
st.write('<div class="feature_text">The features of our webapp are shown below: </div>', unsafe_allow_html=True)
#dividing the page
st.divider()
#creating the features
col1, col2 = st.columns(2)
with col1:
#writing the topic fo the first feature of the app
st.markdown('<div class="topic_header">📂 CSV Content Features</div>', unsafe_allow_html=True)
#writing the content inside the first feature
st.markdown("""
<div class="feature_box">
<div class="feature_text">
• <b>Classification:</b> Upload a CSV and label the data<br>
• <b>Analysis:</b> See explanatory data analysis here <br>
• <b>Q & A:</b> Ask the model questions from your data
</div>
</div>
""", unsafe_allow_html=True)
with col2:
#writing the topic fo the second feature of the app
st.markdown('<div class="topic_header">🎮 Interactive Mini-Game</div>', unsafe_allow_html=True)
#writing the content inside the second feature
st.markdown("""
<div class="feature_box">
<div class="feature_text">
• <b>Classification Test:</b> Play a game where you classify news snippets <br>
</div>
</div>
""", unsafe_allow_html=True)
#dividing the page
st.divider()
#creating the model used for quick classification
st.markdown('<div class="topic_header">🔍 Quick Model Test</div>', unsafe_allow_html=True)
st.write('<div class="feature_text">Type a sentence below to see how our fine-tuned model classifies news:</div>',unsafe_allow_html=True)
#calling and loading the fine tuned model which is uploaded to the hugging face
@st.cache_resource
def load_classifier():
return pipeline("text-classification", model="SuchithTissera/text_analytics_model", truncation=True)
#calling the model which is now loaded into a simple variable
classifier = load_classifier()
#getting the user text
user_text = st.text_area(" ", placeholder="Enter news content here...", height=100)
#carrying out the classification
if st.button("Classify Text"):
if not user_text.strip():
st.warning("Please enter some text.")
else:
with st.spinner("Analyzing..."):
result = classifier(user_text)
st.success("Analysis Complete")
res_col1, res_col2 = st.columns(2)
with res_col1:
st.metric(label="Predicted Category", value=result[0]["label"])
with res_col2:
confidence = round(result[0]["score"] * 100, 2)
st.metric(label="Confidence Score", value=f"{confidence}%")