# app.py # ----------------------------- # 1️⃣ Set Hugging Face / NLTK cache # ----------------------------- import os os.environ["TRANSFORMERS_CACHE"] = "/tmp/cache" os.environ["NLTK_DATA"] = "/tmp/nltk_data" # ----------------------------- # 2️⃣ Streamlit & imports # ----------------------------- import streamlit as st from mca_comment_analyzer import MCACommentAnalyzer # ----------------------------- # 3️⃣ Streamlit UI # ----------------------------- st.set_page_config(page_title="MCA Comment Analyzer Light", layout="wide") st.title("📊 MCA Comment Analyzer Light 📝") st.sidebar.header("Upload or Enter Comments") # Sidebar input upload_file = st.sidebar.file_uploader("Upload CSV/Excel/TXT", type=["csv","xlsx","txt"]) manual_input = st.sidebar.text_area("Or enter comments manually (one per line)") comments = [] if upload_file: import pandas as pd try: if upload_file.name.endswith(".csv"): df_file = pd.read_csv(upload_file) if 'comment' in df_file.columns: comments = df_file['comment'].astype(str).tolist() else: comments = df_file.iloc[:,0].astype(str).tolist() elif upload_file.name.endswith(".xlsx"): df_file = pd.read_excel(upload_file) if 'comment' in df_file.columns: comments = df_file['comment'].astype(str).tolist() else: comments = df_file.iloc[:,0].astype(str).tolist() else: comments = upload_file.read().decode("utf-8").splitlines() except Exception as e: st.error(f"File format not supported or corrupted. {e}") elif manual_input.strip(): comments = manual_input.strip().split("\n") if st.sidebar.button("Analyze"): if comments: analyzer = MCACommentAnalyzer() df, keyword_freq = analyzer.process_comments(comments) st.subheader("📌 Analysis Results") st.dataframe(df, use_container_width=True) st.subheader("📊 Sentiment Distribution") st.bar_chart(df["Sentiment"].value_counts()) st.subheader("☁️ Word Cloud") plt_obj = analyzer.generate_wordcloud(keyword_freq) st.pyplot(plt_obj) else: st.warning("⚠️ Provide comments manually or upload a supported file.")