BinduRP commited on
Commit
6bfcd39
Β·
verified Β·
1 Parent(s): c221fdf

Upload 5 files

Browse files
Dockerfile CHANGED
@@ -1,20 +1,13 @@
1
- FROM python:3.13.5-slim
2
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
14
- RUN pip3 install -r requirements.txt
15
 
16
  EXPOSE 8501
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
-
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
5
+ COPY requirements.txt .
 
 
 
 
6
 
7
+ RUN pip install --no-cache-dir -r requirements.txt
 
8
 
9
+ COPY . .
10
 
11
  EXPOSE 8501
12
 
13
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
Womens Clothing E-Commerce Reviews.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Paste your full Streamlit code here
2
+ # Include:
3
+ # - Chat UI
4
+ # - Preset questions
5
+ # - Filters by rating
6
+ # - Analytics charts (Rating & Sentiment)
7
+ # - RAG chain with Groq LLM
8
+ # - Executive summary generation
9
+ # - PDF and CSV download
10
+ import streamlit as st
11
+ import os
12
+ import pandas as pd
13
+ import tempfile
14
+
15
+ from langchain_groq import ChatGroq
16
+ from langchain_community.vectorstores import FAISS
17
+ from langchain_community.embeddings import HuggingFaceEmbeddings
18
+ from langchain_core.prompts import PromptTemplate
19
+ from langchain_core.runnables import RunnablePassthrough
20
+
21
+ from reportlab.platypus import SimpleDocTemplate, Paragraph
22
+ from reportlab.lib.styles import getSampleStyleSheet
23
+
24
+ # --------------------------------------------------
25
+ # PAGE CONFIG
26
+ # --------------------------------------------------
27
+ st.set_page_config(
28
+ page_title="E-Commerce Review Intelligence",
29
+ layout="wide"
30
+ )
31
+
32
+ st.title("πŸ›οΈ Customer Review Intelligence System")
33
+ st.caption("GenAI-powered insights using RAG (Groq + FAISS)")
34
+
35
+ # --------------------------------------------------
36
+ # SIDEBAR
37
+ # --------------------------------------------------
38
+ st.sidebar.header("πŸ” Configuration")
39
+ groq_key = st.sidebar.text_input("Groq API Key", type="password")
40
+
41
+ if not groq_key:
42
+ st.warning("Please enter your Groq API key")
43
+ st.stop()
44
+
45
+ os.environ["GROQ_API_KEY"] = groq_key
46
+
47
+ rating_filter = st.sidebar.selectbox(
48
+ "Filter by Rating",
49
+ ["All", "Low (1–2)", "Medium (3)", "High (4–5)"]
50
+ )
51
+
52
+ # --------------------------------------------------
53
+ # LOAD DATA
54
+ # --------------------------------------------------
55
+ @st.cache_data
56
+ def load_data():
57
+ df = pd.read_csv("Womens Clothing E-Commerce Reviews.csv")
58
+ df = df.dropna(subset=["Review Text"])
59
+ return df
60
+
61
+ df = load_data()
62
+
63
+ def map_sentiment(r):
64
+ if r <= 2:
65
+ return "Negative"
66
+ elif r == 3:
67
+ return "Neutral"
68
+ else:
69
+ return "Positive"
70
+
71
+ df["Sentiment"] = df["Rating"].apply(map_sentiment)
72
+
73
+ # --------------------------------------------------
74
+ # ANALYTICS
75
+ # --------------------------------------------------
76
+ st.subheader("πŸ“Š Customer Sentiment Overview")
77
+
78
+ col1, col2 = st.columns(2)
79
+ with col1:
80
+ st.bar_chart(df["Rating"].value_counts().sort_index())
81
+ with col2:
82
+ st.bar_chart(df["Sentiment"].value_counts())
83
+
84
+ # --------------------------------------------------
85
+ # LOAD VECTOR STORE
86
+ # --------------------------------------------------
87
+ @st.cache_resource
88
+ def load_vectorstore():
89
+ embeddings = HuggingFaceEmbeddings(
90
+ model_name="sentence-transformers/all-MiniLM-L6-v2"
91
+ )
92
+ return FAISS.load_local(
93
+ "vectorstore",
94
+ embeddings,
95
+ allow_dangerous_deserialization=True
96
+ )
97
+
98
+ vectorstore = load_vectorstore()
99
+ retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
100
+
101
+ # --------------------------------------------------
102
+ # LOAD LLM
103
+ # --------------------------------------------------
104
+ llm = ChatGroq(
105
+ model="llama-3.1-8b-instant",
106
+ temperature=0
107
+ )
108
+
109
+ # --------------------------------------------------
110
+ # RAG PROMPT
111
+ # --------------------------------------------------
112
+ rag_prompt = PromptTemplate(
113
+ input_variables=["context", "question", "rating"],
114
+ template="""
115
+ You are an AI assistant for an e-commerce company.
116
+
117
+ Rating Filter: {rating}
118
+
119
+ Customer Reviews:
120
+ {context}
121
+
122
+ Question:
123
+ {question}
124
+
125
+ Provide clear, actionable business insights.
126
+ """
127
+ )
128
+
129
+ rag_chain = (
130
+ {
131
+ "context": retriever,
132
+ "question": RunnablePassthrough(),
133
+ "rating": RunnablePassthrough()
134
+ }
135
+ | rag_prompt
136
+ | llm
137
+ )
138
+
139
+ # --------------------------------------------------
140
+ # CHAT UI
141
+ # --------------------------------------------------
142
+ if "messages" not in st.session_state:
143
+ st.session_state.messages = []
144
+
145
+ st.subheader("πŸ’¬ Ask Questions")
146
+
147
+ preset = st.selectbox(
148
+ "Quick Business Questions",
149
+ [
150
+ "What are the most common customer complaints?",
151
+ "What do customers say about sizing?",
152
+ "Are customers satisfied with fabric quality?",
153
+ "What improvements should the business prioritize?"
154
+ ]
155
+ )
156
+
157
+ user_input = st.chat_input("Ask your own question")
158
+ question = user_input if user_input else preset
159
+
160
+ if question:
161
+ st.session_state.messages.append(
162
+ {"role": "user", "content": question}
163
+ )
164
+
165
+ response = rag_chain.invoke(
166
+ {"question": question, "rating": rating_filter}
167
+ )
168
+
169
+ st.session_state.messages.append(
170
+ {"role": "assistant", "content": response.content}
171
+ )
172
+
173
+ for msg in st.session_state.messages:
174
+ st.chat_message(msg["role"]).write(msg["content"])
175
+
176
+ # --------------------------------------------------
177
+ # EXECUTIVE SUMMARY
178
+ # --------------------------------------------------
179
+ st.subheader("πŸ“„ Executive Summary")
180
+
181
+ exec_prompt = PromptTemplate(
182
+ input_variables=["reviews"],
183
+ template="""
184
+ Generate an executive summary covering:
185
+ - Overall sentiment
186
+ - Top complaints
187
+ - Key strengths
188
+ - Business recommendations
189
+
190
+ Reviews:
191
+ {reviews}
192
+ """
193
+ )
194
+
195
+ summary_text = None
196
+
197
+ if st.button("Generate Executive Summary"):
198
+ sample_reviews = " ".join(df["Review Text"].sample(30))
199
+ summary_text = (exec_prompt | llm).invoke(
200
+ {"reviews": sample_reviews}
201
+ ).content
202
+ st.success(summary_text)
203
+
204
+ # --------------------------------------------------
205
+ # PDF EXPORT
206
+ # --------------------------------------------------
207
+ def generate_pdf(text):
208
+ styles = getSampleStyleSheet()
209
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
210
+ doc = SimpleDocTemplate(temp_file.name)
211
+ doc.build([
212
+ Paragraph("<b>Executive Summary</b>", styles["Title"]),
213
+ Paragraph(text.replace("\n", "<br/>"), styles["Normal"])
214
+ ])
215
+ return temp_file.name
216
+
217
+ if summary_text:
218
+ pdf_path = generate_pdf(summary_text)
219
+ with open(pdf_path, "rb") as f:
220
+ st.download_button(
221
+ "πŸ“₯ Download Executive Summary (PDF)",
222
+ f,
223
+ file_name="executive_summary.pdf",
224
+ mime="application/pdf"
225
+ )
226
+
227
+ # --------------------------------------------------
228
+ # CSV EXPORT
229
+ # --------------------------------------------------
230
+ st.subheader("πŸ“₯ Download Review Data")
231
+
232
+ csv = df[["Review Text", "Rating", "Sentiment"]].to_csv(index=False).encode("utf-8")
233
+
234
+ st.download_button(
235
+ "Download CSV",
236
+ csv,
237
+ "customer_reviews.csv",
238
+ "text/csv"
239
+ )
240
+ st.write("STREAMLIT APP IS RUNNING SUCCESSFULLY")
requirements.txt CHANGED
@@ -1,3 +1,9 @@
1
- altair
2
  pandas
3
- streamlit
 
 
 
 
 
 
 
1
+ streamlit
2
  pandas
3
+ numpy
4
+ scikit-learn
5
+ faiss-cpu
6
+ langchain-community
7
+ langchain-core
8
+ sentence-transformers
9
+ groq
vectorstore.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:825f0377352c9618a085d7c1dc2d7437ee7d5740ad034e29acd303de4182feae
3
+ size 36503127