Spaces:
Runtime error
Runtime error
File size: 1,976 Bytes
4aaebc3 | 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 | # app.py
import streamlit as st
from modules.data_loader import load_texts
from modules.preprocessing import preprocess_texts
from modules.sentiment_analysis import analyze_sentiment
from modules.summarizer import summarize_texts
from modules.visualization import generate_wordcloud, plot_sentiment_distribution
from modules.utils import save_results_to_csv, display_dataframe
from config.settings import DATA_PATH
# Title
st.title("π Sentiment Analysis of E-Consultation Comments")
st.write("AI-powered tool for sentiment analysis, summarization, and visualization.")
# File uploader
uploaded_file = st.file_uploader("Upload a .txt file (one comment per line)", type=["txt"])
if uploaded_file:
# Save uploaded file
with open(DATA_PATH, "wb") as f:
f.write(uploaded_file.read())
st.success("β
File uploaded successfully!")
# Load data
texts = load_texts(DATA_PATH)
st.write(f"Loaded **{len(texts)}** comments.")
# Preprocess
clean_texts = preprocess_texts(texts)
# Sentiment Analysis
st.subheader("π Sentiment Analysis")
sentiment_results = analyze_sentiment(clean_texts)
sentiment_chart = plot_sentiment_distribution(sentiment_results)
st.image(sentiment_chart, caption="Sentiment Distribution")
# Summarization
st.subheader("π Summarization")
summaries = summarize_texts(clean_texts)
st.write("Here are some summaries:")
for s in summaries[:5]:
st.write(f"- {s['summary']}")
# Word Cloud
st.subheader("β Word Cloud")
wc_image = generate_wordcloud(clean_texts)
st.image(wc_image, caption="Word Cloud of Comments")
# Results Table
st.subheader("π Results Table")
df = display_dataframe(sentiment_results, summaries)
st.dataframe(df)
# Save results
results_path = save_results_to_csv(sentiment_results, summaries)
st.download_button("π₯ Download Results CSV", data=open(results_path, "rb"), file_name="results.csv")
|