Harshb11 commited on
Commit
405c478
·
verified ·
1 Parent(s): c85badc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -26
app.py CHANGED
@@ -1,43 +1,65 @@
1
  # app.py
2
 
3
  # -----------------------------
4
- # 1️⃣ Hugging Face cache fix
5
  # -----------------------------
6
- # app.py ke top me (Streamlit import se pehle)
7
  import os
8
- os.environ["TRANSFORMERS_CACHE"] = "/tmp/cache" # Hugging Face cache
9
- os.environ["NLTK_DATA"] = "/tmp/nltk_data" # NLTK writable cache
10
-
11
- import nltk
12
- nltk.download('stopwords', download_dir="/tmp/nltk_data", quiet=True)
13
-
14
 
15
  # -----------------------------
16
- # 2️⃣ Streamlit import
17
  # -----------------------------
18
  import streamlit as st
 
19
 
20
  # -----------------------------
21
- # 3️⃣ Local module import
22
  # -----------------------------
23
- from mca_comment_analyzer import MCACommentAnalyzer # check class name in your file
 
 
24
 
25
- # -----------------------------
26
- # 4️⃣ Streamlit App
27
- # -----------------------------
28
- st.title("MCA Comment Analyzer Light 📝")
29
 
30
- # Example usage
31
- st.write("Upload your comment file or input text below:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- user_input = st.text_area("Enter comment text:")
 
 
 
34
 
35
- if st.button("Analyze"):
36
- if user_input.strip() == "":
37
- st.warning("Please enter some text!")
38
- else:
39
- analyzer = MCACommentAnalyzer() # class ka sahi naam
40
- result = analyzer.analyze_comment(user_input) # method ka sahi naam
41
- st.success("Analysis Result:")
42
- st.write(result)
43
 
 
 
 
 
 
 
1
  # app.py
2
 
3
  # -----------------------------
4
+ # 1️⃣ Set Hugging Face cache
5
  # -----------------------------
 
6
  import os
7
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/cache"
8
+ os.environ["NLTK_DATA"] = "/tmp/nltk_data"
 
 
 
 
9
 
10
  # -----------------------------
11
+ # 2️⃣ Streamlit & NLP imports
12
  # -----------------------------
13
  import streamlit as st
14
+ from mca_comment_analyzer import MCACommentAnalyzer
15
 
16
  # -----------------------------
17
+ # 3️⃣ Streamlit UI
18
  # -----------------------------
19
+ st.set_page_config(page_title="MCA Comment Analyzer Light", layout="wide")
20
+ st.title("📊 MCA Comment Analyzer Light 📝")
21
+ st.sidebar.header("Upload or Enter Comments")
22
 
23
+ # Sidebar input
24
+ upload_file = st.sidebar.file_uploader("Upload CSV/Excel/TXT", type=["csv","xlsx","txt"])
25
+ manual_input = st.sidebar.text_area("Or enter comments manually (one per line)")
 
26
 
27
+ comments = []
28
+ if upload_file:
29
+ import pandas as pd
30
+ try:
31
+ if upload_file.name.endswith(".csv"):
32
+ df_file = pd.read_csv(upload_file)
33
+ if 'comment' in df_file.columns:
34
+ comments = df_file['comment'].astype(str).tolist()
35
+ else:
36
+ comments = df_file.iloc[:,0].astype(str).tolist()
37
+ elif upload_file.name.endswith(".xlsx"):
38
+ df_file = pd.read_excel(upload_file)
39
+ if 'comment' in df_file.columns:
40
+ comments = df_file['comment'].astype(str).tolist()
41
+ else:
42
+ comments = df_file.iloc[:,0].astype(str).tolist()
43
+ else:
44
+ comments = upload_file.read().decode("utf-8").splitlines()
45
+ except Exception as e:
46
+ st.error(f"File format not supported or corrupted. {e}")
47
+ elif manual_input.strip():
48
+ comments = manual_input.strip().split("\n")
49
 
50
+ if st.sidebar.button("Analyze"):
51
+ if comments:
52
+ analyzer = MCACommentAnalyzer()
53
+ df, keyword_freq = analyzer.process_comments(comments)
54
 
55
+ st.subheader("📌 Analysis Results")
56
+ st.dataframe(df, use_container_width=True)
57
+
58
+ st.subheader("📊 Sentiment Distribution")
59
+ st.bar_chart(df["Sentiment"].value_counts())
 
 
 
60
 
61
+ st.subheader("☁️ Word Cloud")
62
+ plt_obj = analyzer.generate_wordcloud(keyword_freq)
63
+ st.pyplot(plt_obj)
64
+ else:
65
+ st.warning("⚠️ Provide comments manually or upload a supported file.")