Spaces:
Sleeping
Sleeping
File size: 2,311 Bytes
3d7895f 7699ca2 3d7895f 5188dda 3d7895f 405c478 7699ca2 3d7895f 5188dda 3d7895f 405c478 7699ca2 3d7895f 405c478 3d7895f 405c478 7699ca2 405c478 7699ca2 405c478 7699ca2 405c478 7699ca2 405c478 c85badc 405c478 |
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 |
# 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.")
|