Spaces:
Runtime error
Runtime error
| # 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") | |