Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243# app.py# -----------------------------# 1️⃣ Hugging Face cache fix# -----------------------------# app.py ke top me (Streamlit import se pehle)import osos.environ["TRANSFORMERS_CACHE"] = "/tmp/cache" # Hugging Face cacheos.environ["NLTK_DATA"] = "/tmp/nltk_data" # NLTK writable cacheimport nltknltk.download('stopwords', download_dir="/tmp/nltk_data", quiet=True)# -----------------------------# 2️⃣ Streamlit import# -----------------------------import streamlit as st# -----------------------------# 3️⃣ Local module import# -----------------------------from mca_comment_analyzer import MCACommentAnalyzer # check class name in your file# -----------------------------# 4️⃣ Streamlit App# -----------------------------st.title("MCA Comment Analyzer Light 📝")# Example usagest.write("Upload your comment file or input text below:")user_input = st.text_area("Enter comment text:")if st.button("Analyze"):if user_input.strip() == "":st.warning("Please enter some text!")else:analyzer = MCACommentAnalyzer() # class ka sahi naamresult = analyzer.analyze_comment(user_input) # method ka sahi naamst.success("Analysis Result:")st.write(result)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465# app.py# -----------------------------# 1️⃣ Set Hugging Face cache# -----------------------------import osos.environ["TRANSFORMERS_CACHE"] = "/tmp/cache"os.environ["NLTK_DATA"] = "/tmp/nltk_data"# -----------------------------# 2️⃣ Streamlit & NLP imports# -----------------------------import streamlit as stfrom 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 inputupload_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 pdtry: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.")
app.py+48-26