Spaces:
Runtime error

RimaAlaya commited on
Commit
4cb68ea
Β·
verified Β·
1 Parent(s): 82ca8fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +392 -197
app.py CHANGED
@@ -1,291 +1,486 @@
1
  # app.py
2
  """
3
- CineRAG - Cinema Secrets with REAL feedback
 
4
  """
5
 
6
  import streamlit as st
 
7
  from cinema_secrets_rag import CinemaSecretsRAG
8
- from metrics_tracker import MetricsTracker
9
  import plotly.graph_objects as go
 
10
  import time
11
 
12
- st.set_page_config(page_title="CineRAG", page_icon="🎬", layout="wide")
 
 
 
 
 
13
 
14
- # CSS - CLEANER, less blank space
15
  st.markdown("""
16
  <style>
 
17
  #MainMenu {visibility: hidden;}
18
  footer {visibility: hidden;}
19
  header {visibility: hidden;}
20
  [data-testid="stToolbar"] {display: none !important;}
21
-
22
  .block-container {
23
  padding-top: 1rem !important;
24
  padding-bottom: 0rem !important;
25
- max-width: 1400px !important;
26
  }
27
-
 
 
28
  .stApp {
29
- background-color: #0a0a0a;
 
 
 
30
  }
31
-
32
- /* Input styling */
33
- .stTextInput input {
34
- background: #1a1a1a;
35
- border: 2px solid #ff4444;
36
- border-radius: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  color: white;
38
- font-size: 1.1rem;
39
- padding: 12px;
 
 
 
40
  }
41
-
42
- /* Button styling */
43
- .stButton button {
44
- background: linear-gradient(90deg, #ff4444, #ff6b6b);
45
  color: white;
46
  border: none;
47
- border-radius: 8px;
48
- padding: 10px 30px;
49
- font-weight: 600;
50
- transition: 0.3s;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
-
53
- .stButton button:hover {
54
- transform: translateY(-2px);
55
- box-shadow: 0 5px 15px rgba(255,68,68,0.4);
56
  }
57
-
58
- /* Answer box */
59
- .answer-box {
60
- background: linear-gradient(135deg, #1a1a1a, #2a1a1a);
61
- border-left: 4px solid #ff4444;
62
  padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  border-radius: 10px;
64
- margin: 20px 0;
 
 
65
  }
66
-
67
- /* Feedback buttons - INLINE */
68
- div[data-testid="column"] button {
69
- width: 100%;
 
 
 
 
 
 
 
70
  }
71
  </style>
72
  """, unsafe_allow_html=True)
73
 
 
 
74
  @st.cache_resource
75
- def load_rag():
76
  return CinemaSecretsRAG()
77
 
78
- rag = load_rag()
79
 
80
- # Header
81
- st.markdown("# 🎬 CineRAG - Cinema Secrets")
82
- st.markdown("*Spilling behind-the-scenes tea since 2025*")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  # Tabs
85
- tab1, tab2, tab3 = st.tabs(["πŸ” Ask", "πŸ“Š Metrics", "ℹ️ About"])
86
 
 
87
  with tab1:
 
 
 
88
  query = st.text_input(
89
- "Ask anything about movies",
90
- placeholder="What secrets are there about Inception?",
91
- key="main_query"
 
92
  )
93
-
94
- col1, col2, col3 = st.columns([1, 1, 3])
95
- with col1:
96
- use_llm = st.checkbox("AI Answer", value=True)
97
  with col2:
98
- search = st.button("πŸ”₯ Search", type="primary")
99
-
100
- if query and search:
101
- start = time.time()
102
- result = rag.ask(query, top_k=5, use_llm=use_llm)
103
- elapsed = time.time() - start
104
-
105
- # Store result in session state
 
 
 
 
 
 
106
  st.session_state.last_result = result
107
  st.session_state.last_elapsed = elapsed
108
-
109
- # Show result if exists
110
- if 'last_result' in st.session_state:
111
- result = st.session_state.last_result
112
- elapsed = st.session_state.last_elapsed
113
-
114
  st.markdown(f"""
115
- <div class="answer-box">
116
- <h3>πŸ’¬ Answer</h3>
117
- <p style="font-size: 1.1rem; line-height: 1.7;">{result['answer']}</p>
 
 
118
  </div>
119
  """, unsafe_allow_html=True)
120
-
 
121
  if result['has_secrets']:
122
- st.success("🎬 Contains behind-the-scenes secrets!")
123
-
124
- st.caption(f"⚑ {elapsed:.2f}s")
125
-
126
- # FEEDBACK - REAL immediate response
127
- st.markdown("---")
128
- st.markdown("#### Was this helpful?")
129
 
130
  col1, col2, col3, col4, col5 = st.columns(5)
131
 
132
  with col1:
133
- if st.button("πŸ‘ Yes", key=f"yes_{result['query_id']}"):
134
  rag.feedback.save_feedback(result['query_id'], rating=1)
135
- st.success("βœ… Thanks!")
136
  st.balloons()
137
 
138
  with col2:
139
- if st.button("πŸ‘Ž No", key=f"no_{result['query_id']}"):
140
  st.session_state[f'feedback_{result["query_id"]}'] = True
141
 
142
- # Feedback form
143
  if st.session_state.get(f'feedback_{result["query_id"]}', False):
144
  with st.form(key=f'form_{result["query_id"]}'):
145
- feedback_text = st.text_area("What was wrong?")
146
  submitted = st.form_submit_button("Submit")
147
 
148
  if submitted:
149
  rag.feedback.save_feedback(result['query_id'], rating=0, feedback_text=feedback_text)
150
- st.success("βœ… Feedback saved!")
151
  del st.session_state[f'feedback_{result["query_id"]}']
152
  st.rerun()
153
-
154
  # Sources
155
  st.markdown("---")
156
- st.markdown("#### πŸ“š Sources")
157
-
158
- for i, src in enumerate(result['sources'][:3], 1):
159
- secret = "🎬" if src['is_secret'] else ""
160
- with st.expander(f"{i}. {src['movie_title']} {secret}", expanded=(i==1)):
161
- st.write(src['text'])
162
- st.caption(f"Type: {src['chunk_type']} | Relevance: {src['relevance_score']:.2f}")
163
 
 
 
 
 
 
 
 
 
 
 
164
  with tab2:
165
- st.markdown("### πŸ“Š System Metrics")
166
-
167
- # Refresh button
168
- if st.button("πŸ”„ Refresh Metrics"):
169
- st.cache_resource.clear()
170
- st.rerun()
171
-
172
  tracker = MetricsTracker()
173
- days = st.selectbox("Period", [1, 7, 30], index=1)
 
174
  report = tracker.generate_report(days=days)
175
-
176
- # Overview
177
- col1, col2, col3, col4 = st.columns(4)
178
-
179
- with col1:
180
- st.metric("Queries", report['overview']['total_queries'])
181
- with col2:
182
- sat = report['performance']['satisfaction_rate']
183
- st.metric("Satisfaction", f"{sat:.0%}")
184
- with col3:
185
- lat = report['performance']['latency']['avg_ms']
186
- st.metric("Latency", f"{lat:.0f}ms")
187
- with col4:
188
- cost = report['costs']['estimated_cost_usd']
189
- st.metric("Cost", f"${cost:.4f}", help="Hypothetical (using free Groq)")
190
-
191
- st.markdown("---")
192
-
193
- # Charts
194
  col1, col2 = st.columns(2)
195
-
196
  with col1:
197
- st.markdown("#### ⚑ Latency Distribution")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  latency = report['performance']['latency']
199
-
200
- fig = go.Figure(data=[
201
- go.Bar(
202
- x=['Avg', 'P95', 'P99', 'Max'],
203
- y=[latency['avg_ms'], latency['p95_ms'], latency['p99_ms'], latency['max_ms']],
204
- marker_color=['#4CAF50', '#FFC107', '#FF9800', '#F44336']
205
- )
206
- ])
207
- fig.update_layout(
208
- height=300,
209
- paper_bgcolor='rgba(0,0,0,0)',
210
- plot_bgcolor='rgba(0,0,0,0)',
211
- font_color='white'
212
- )
213
  st.plotly_chart(fig, use_container_width=True)
214
-
 
215
  with col2:
216
- st.markdown("#### 🎬 Query Types")
217
- secrets = report['usage']['secrets_distribution']
218
-
219
- fig = go.Figure(data=[
220
- go.Pie(
221
- labels=['With Secrets', 'Basic Info'],
222
- values=[secrets['with_secrets'], secrets['without_secrets']],
223
- hole=0.4,
224
- marker_colors=['#ff4444', '#4444ff']
225
- )
226
- ])
227
- fig.update_layout(
228
- height=300,
229
- paper_bgcolor='rgba(0,0,0,0)',
230
- font_color='white',
231
- showlegend=True
232
- )
233
  st.plotly_chart(fig, use_container_width=True)
234
-
235
- # Quality analysis
236
- st.markdown("---")
237
- st.markdown("#### ⚠️ Quality Issues")
238
-
239
- failures = report['quality']
240
- if failures['total_failures'] > 0:
241
- st.warning(f"{failures['total_failures']} queries got negative feedback")
242
-
243
- for category, count in failures['failure_categories'].items():
244
- if count > 0:
245
- st.write(f"- {category.replace('_', ' ').title()}: {count}")
246
- else:
247
- st.success("No complaints in this period! πŸŽ‰")
248
 
 
249
  with tab3:
 
 
250
  col1, col2 = st.columns(2)
251
-
252
  with col1:
253
  st.markdown("""
254
- ### 🎯 What is CineRAG?
255
-
256
- A RAG system for cinema lovers that goes beyond IMDB:
257
-
258
- - 🎬 Behind-the-scenes production stories
259
- - 🎭 Casting secrets and actor prep
260
- - πŸŽ₯ Filming challenges
261
- - πŸ“Ί Reception and controversies
262
-
263
- ### πŸ”§ Tech Stack
264
-
265
- - **Hybrid Search**: BM25 + Semantic embeddings
266
- - **LLM**: Groq's Mixtral-8x7b
267
- - **Vector DB**: FAISS
268
- - **Framework**: LangChain
269
  """)
270
-
271
  with col2:
272
- stats = rag.get_statistics()
273
-
274
  st.markdown("""
275
- ### πŸ“Š Data
276
- """)
277
- st.metric("Movies", stats['total_movies'])
278
- st.metric("With Secrets", "252")
279
- st.metric("Total Chunks", stats['total_chunks'])
280
- st.metric("Secret Chunks", stats['secret_chunks'])
281
-
282
- st.markdown("""
283
- ### πŸ‘©β€πŸ’» Built By
284
-
285
- **Rima Alaya** - AI/ML Engineer
286
-
287
  [GitHub](https://github.com/RimaAlaya) | [LinkedIn](https://linkedin.com/in/rima-alaya)
288
  """)
289
 
 
290
  st.markdown("---")
291
- st.caption("🎬 CineRAG v2.0 | Powered by Groq (free tier)")
 
 
 
 
 
1
  # app.py
2
  """
3
+ CineRAG - GOSSIP MODE
4
+ Spilling Cinema's Hottest Secrets β˜•
5
  """
6
 
7
  import streamlit as st
8
+ import json
9
  from cinema_secrets_rag import CinemaSecretsRAG
 
10
  import plotly.graph_objects as go
11
+ import plotly.express as px
12
  import time
13
 
14
+ # Page config
15
+ st.set_page_config(
16
+ page_title="CineRAG - Cinema Gossip",
17
+ page_icon="🍿",
18
+ layout="wide"
19
+ )
20
 
21
+ # GOSSIP THEME - Make it POP
22
  st.markdown("""
23
  <style>
24
+ /* 1. HIDE STREAMLIT BRANDING & DEPLOY BAR */
25
  #MainMenu {visibility: hidden;}
26
  footer {visibility: hidden;}
27
  header {visibility: hidden;}
28
  [data-testid="stToolbar"] {display: none !important;}
29
+ /* 3. REMOVE EXTRA WHITESPACE (The "Blank Bars") - FIXED */
30
  .block-container {
31
  padding-top: 1rem !important;
32
  padding-bottom: 0rem !important;
33
+ max-width: 95% !important;
34
  }
35
+ div[data-testid="stVerticalBlock"] { gap: 1rem; }
36
+
37
+ /* Cinema gossip vibe */
38
  .stApp {
39
+ background-color: #1a0000;
40
+ background-image:
41
+ repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(139, 0, 0, 0.03) 35px, rgba(139, 0, 0, 0.03) 70px),
42
+ url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0l5 10h10l-8 8 3 10-10-5-10 5 3-10-8-8h10z' fill='%238b0000' fill-opacity='0.03'/%3E%3C/svg%3E");
43
  }
44
+ /* Gossip column header */
45
+ .gossip-header {
46
+ background: linear-gradient(135deg, #8b0000 0%, #dc143c 100%);
47
+ border-radius: 20px;
48
+ padding: 40px;
49
+ margin: 20px 0 40px 0;
50
+ box-shadow: 0 10px 40px rgba(220, 20, 60, 0.3);
51
+ border: 3px solid #ff1744;
52
+ }
53
+ .gossip-title {
54
+ font-size: 3.5rem;
55
+ font-weight: 900;
56
+ color: #fff;
57
+ text-align: center;
58
+ text-shadow: 3px 3px 6px rgba(0,0,0,0.7);
59
+ letter-spacing: 3px;
60
+ }
61
+ .gossip-subtitle {
62
+ text-align: center;
63
+ font-size: 1.3rem;
64
+ color: #ffd700;
65
+ margin-top: 10px;
66
+ font-style: italic;
67
+ }
68
+ /* Sidebar stats - vertical */
69
+ [data-testid="stSidebar"] {
70
+ background: linear-gradient(180deg, #1a0000 0%, #2d0000 100%);
71
+ border-right: 3px solid #8b0000;
72
+ }
73
+ .stat-box-vertical {
74
+ background: linear-gradient(135deg, rgba(139, 0, 0, 0.3), rgba(220, 20, 60, 0.2));
75
+ border: 2px solid #8b0000;
76
+ border-radius: 15px;
77
+ padding: 25px;
78
+ margin: 15px 0;
79
+ text-align: center;
80
+ box-shadow: 0 5px 15px rgba(220, 20, 60, 0.2);
81
+ }
82
+ .stat-emoji {
83
+ font-size: 2.5rem;
84
+ margin-bottom: 10px;
85
+ }
86
+ .stat-number {
87
+ font-size: 2.5rem;
88
+ font-weight: 900;
89
+ color: #ff1744;
90
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
91
+ }
92
+ .stat-label {
93
+ font-size: 0.95rem;
94
+ color: #ffd700;
95
+ text-transform: uppercase;
96
+ letter-spacing: 2px;
97
+ margin-top: 8px;
98
+ }
99
+ /* Chat-style query box */
100
+ .query-container {
101
+ background: rgba(220, 20, 60, 0.1);
102
+ border: 2px solid #8b0000;
103
+ border-radius: 15px;
104
+ padding: 25px;
105
+ margin: 30px 0;
106
+ }
107
+ .stTextInput > div > div > input {
108
+ background: rgba(0, 0, 0, 0.6);
109
+ border: 2px solid #ff1744;
110
+ border-radius: 12px;
111
+ padding: 18px 25px;
112
+ font-size: 1.2rem;
113
  color: white;
114
+ box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
115
+ }
116
+ .stTextInput > div > div > input:focus {
117
+ border-color: #ffd700;
118
+ box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
119
  }
120
+ /* Post button - Twitter style */
121
+ .stButton > button {
122
+ background: linear-gradient(90deg, #ff1744, #f50057);
 
123
  color: white;
124
  border: none;
125
+ border-radius: 25px;
126
+ padding: 15px 50px;
127
+ font-weight: 700;
128
+ font-size: 1.15rem;
129
+ text-transform: uppercase;
130
+ letter-spacing: 1px;
131
+ box-shadow: 0 5px 20px rgba(255, 23, 68, 0.5);
132
+ transition: all 0.3s;
133
+ }
134
+ .stButton > button:hover {
135
+ transform: translateY(-3px);
136
+ box-shadow: 0 8px 30px rgba(255, 23, 68, 0.7);
137
+ }
138
+ /* Answer - Gossip card style */
139
+ .gossip-answer {
140
+ background: linear-gradient(135deg, rgba(139, 0, 0, 0.4), rgba(220, 20, 60, 0.2));
141
+ border-left: 6px solid #ff1744;
142
+ border-radius: 15px;
143
+ padding: 30px;
144
+ margin: 25px 0;
145
+ box-shadow: 0 8px 25px rgba(220, 20, 60, 0.3);
146
+ border: 1px solid #8b0000;
147
+ }
148
+ .tea-emoji {
149
+ font-size: 2rem;
150
+ margin-right: 10px;
151
+ animation: steam 2s infinite;
152
+ }
153
+ @keyframes steam {
154
+ 0%, 100% { transform: translateY(0px); }
155
+ 50% { transform: translateY(-5px); }
156
+ }
157
+ /* Secret badge - EXTRA */
158
+ .secret-pill {
159
+ background: linear-gradient(90deg, #ff1744, #ffd700);
160
+ color: #000;
161
+ padding: 8px 20px;
162
+ border-radius: 20px;
163
+ font-size: 0.9rem;
164
+ font-weight: 800;
165
+ display: inline-block;
166
+ margin: 10px 5px;
167
+ box-shadow: 0 3px 10px rgba(255, 215, 0, 0.4);
168
+ animation: glow 2s infinite;
169
  }
170
+ @keyframes glow {
171
+ 0%, 100% { box-shadow: 0 3px 10px rgba(255, 215, 0, 0.4); }
172
+ 50% { box-shadow: 0 5px 20px rgba(255, 215, 0, 0.8); }
 
173
  }
174
+ /* Sources - Cards */
175
+ .source-gossip-card {
176
+ background: rgba(0, 0, 0, 0.4);
177
+ border: 2px solid #8b0000;
178
+ border-radius: 12px;
179
  padding: 20px;
180
+ margin: 15px 0;
181
+ transition: all 0.3s;
182
+ }
183
+ .source-gossip-card:hover {
184
+ border-color: #ff1744;
185
+ transform: translateX(5px);
186
+ box-shadow: 0 5px 20px rgba(255, 23, 68, 0.3);
187
+ }
188
+ /* Tabs */
189
+ .stTabs [data-baseweb="tab-list"] {
190
+ gap: 15px;
191
+ background: transparent;
192
+ }
193
+ .stTabs [data-baseweb="tab"] {
194
+ background: rgba(139, 0, 0, 0.3);
195
+ border: 2px solid #8b0000;
196
  border-radius: 10px;
197
+ color: white;
198
+ padding: 12px 25px;
199
+ font-weight: 600;
200
  }
201
+ .stTabs [aria-selected="true"] {
202
+ background: linear-gradient(90deg, #ff1744, #f50057);
203
+ border-color: #ff1744;
204
+ }
205
+ /* Metrics plots */
206
+ .plot-container {
207
+ background: rgba(0, 0, 0, 0.4);
208
+ border: 2px solid #8b0000;
209
+ border-radius: 12px;
210
+ padding: 20px;
211
+ margin: 15px 0;
212
  }
213
  </style>
214
  """, unsafe_allow_html=True)
215
 
216
+
217
+ # Initialize
218
  @st.cache_resource
219
+ def load_rag_system():
220
  return CinemaSecretsRAG()
221
 
 
222
 
223
+ rag = load_rag_system()
224
+
225
+ # Sidebar with VERTICAL stats
226
+ with st.sidebar:
227
+ st.markdown("""
228
+ <div style="text-align: center; margin: 20px 0;">
229
+ <h2 style="color: #ff1744; font-size: 1.5rem;">🍿 GOSSIP STATS</h2>
230
+ </div>
231
+ """, unsafe_allow_html=True)
232
+
233
+ stats = rag.get_statistics()
234
+
235
+ st.markdown(f"""
236
+ <div class="stat-box-vertical">
237
+ <div class="stat-emoji">🎬</div>
238
+ <div class="stat-number">{stats['total_movies']}</div>
239
+ <div class="stat-label">Movies</div>
240
+ </div>
241
+ """, unsafe_allow_html=True)
242
+
243
+ st.markdown(f"""
244
+ <div class="stat-box-vertical">
245
+ <div class="stat-emoji">🀫</div>
246
+ <div class="stat-number">{stats['secret_chunks']}</div>
247
+ <div class="stat-label">Secrets</div>
248
+ </div>
249
+ """, unsafe_allow_html=True)
250
+
251
+ st.markdown(f"""
252
+ <div class="stat-box-vertical">
253
+ <div class="stat-emoji">πŸ“Š</div>
254
+ <div class="stat-number">{stats['total_chunks']}</div>
255
+ <div class="stat-label">Total Facts</div>
256
+ </div>
257
+ """, unsafe_allow_html=True)
258
+
259
+ llm_emoji = "πŸ€–" if stats['has_llm'] else "⚠️"
260
+ st.markdown(f"""
261
+ <div class="stat-box-vertical">
262
+ <div class="stat-emoji">{llm_emoji}</div>
263
+ <div class="stat-number">{"AI" if stats['has_llm'] else "OFF"}</div>
264
+ <div class="stat-label">Powered By</div>
265
+ </div>
266
+ """, unsafe_allow_html=True)
267
+
268
+ st.markdown("---")
269
+ st.markdown("### πŸ”₯ Quick Tea")
270
+ if st.button("🎬 Inception Secrets", use_container_width=True):
271
+ st.session_state.quick_query = "What secrets about Inception?"
272
+ if st.button("πŸ¦‡ Dark Knight Tea", use_container_width=True):
273
+ st.session_state.quick_query = "Behind scenes Dark Knight"
274
+ if st.button("⚑ Matrix Gossip", use_container_width=True):
275
+ st.session_state.quick_query = "Matrix production secrets"
276
+
277
+ # Main header
278
+ st.markdown("""
279
+ <div class="gossip-header">
280
+ <h1 class="gossip-title">🍿 CineRAG</h1>
281
+ <p class="gossip-subtitle">Your Source for Cinema's Hottest Secrets & Gossip</p>
282
+ </div>
283
+ """, unsafe_allow_html=True)
284
 
285
  # Tabs
286
+ tab1, tab2, tab3 = st.tabs(["β˜• SPILL THE TEA", "πŸ“Š THE RECEIPTS", "ℹ️ ABOUT"])
287
 
288
+ # Tab 1: Main gossip
289
  with tab1:
290
+ st.markdown('<div class="query-container">', unsafe_allow_html=True)
291
+ st.markdown("### πŸ’¬ What's the tea?")
292
+
293
  query = st.text_input(
294
+ "",
295
+ placeholder="Ask me ANYTHING about movies... (e.g., What REALLY happened on set of Titanic?)",
296
+ label_visibility="collapsed",
297
+ value=st.session_state.get('quick_query', '')
298
  )
299
+
300
+ col1, col2, col3 = st.columns([2, 1, 2])
 
 
301
  with col2:
302
+ post_button = st.button("πŸ”₯ SPILL IT", use_container_width=True)
303
+
304
+ st.markdown('</div>', unsafe_allow_html=True)
305
+
306
+ if query and (post_button or st.session_state.get('quick_query')):
307
+ with st.spinner("β˜• Brewing the tea..."):
308
+ start_time = time.time()
309
+ result = rag.ask(query, top_k=5, use_llm=True)
310
+ elapsed = time.time() - start_time
311
+
312
+ if 'quick_query' in st.session_state:
313
+ del st.session_state.quick_query
314
+
315
+ # Store for feedback
316
  st.session_state.last_result = result
317
  st.session_state.last_elapsed = elapsed
318
+
319
+ # Answer
 
 
 
 
320
  st.markdown(f"""
321
+ <div class="gossip-answer">
322
+ <h3><span class="tea-emoji">β˜•</span> THE TEA</h3>
323
+ <p style="font-size: 1.15rem; line-height: 1.8; color: #fff; margin-top: 15px;">
324
+ {result['answer']}
325
+ </p>
326
  </div>
327
  """, unsafe_allow_html=True)
328
+
329
+ # Badges
330
  if result['has_secrets']:
331
+ st.markdown('<span class="secret-pill">🎬 INSIDER SECRETS REVEALED</span>', unsafe_allow_html=True)
332
+
333
+ st.markdown(f'<span class="secret-pill">⚑ {elapsed:.2f}s</span>', unsafe_allow_html=True)
334
+
335
+ # === ROBUST FEEDBACK SYSTEM (replaced) ===
336
+ st.markdown("### πŸ—³οΈ Rate this tea")
 
337
 
338
  col1, col2, col3, col4, col5 = st.columns(5)
339
 
340
  with col1:
341
+ if st.button("πŸ‘ HOT TEA", key=f"yes_{result['query_id']}"):
342
  rag.feedback.save_feedback(result['query_id'], rating=1)
343
+ st.success("Spicy! πŸ”₯")
344
  st.balloons()
345
 
346
  with col2:
347
+ if st.button("πŸ‘Ž LUKEWARM", key=f"no_{result['query_id']}"):
348
  st.session_state[f'feedback_{result["query_id"]}'] = True
349
 
350
+ # Feedback form if needed
351
  if st.session_state.get(f'feedback_{result["query_id"]}', False):
352
  with st.form(key=f'form_{result["query_id"]}'):
353
+ feedback_text = st.text_area("What went wrong?")
354
  submitted = st.form_submit_button("Submit")
355
 
356
  if submitted:
357
  rag.feedback.save_feedback(result['query_id'], rating=0, feedback_text=feedback_text)
358
+ st.success("Thanks for the feedback!")
359
  del st.session_state[f'feedback_{result["query_id"]}']
360
  st.rerun()
361
+
362
  # Sources
363
  st.markdown("---")
364
+ st.markdown("### πŸ“° SOURCES (Receipts)")
365
+
366
+ for i, source in enumerate(result['sources'], 1):
367
+ secret_badge = "🀫 EXCLUSIVE" if source['is_secret'] else ""
 
 
 
368
 
369
+ st.markdown(f"""
370
+ <div class="source-gossip-card">
371
+ <h4 style="color: #ff1744;">{i}. {source['movie_title']} {secret_badge}</h4>
372
+ <p style="color: #ffd700; font-size: 0.85rem; margin: 5px 0;">[{source['chunk_type']}]</p>
373
+ <p style="color: #ddd; line-height: 1.6; margin: 10px 0;">{source['text'][:300]}...</p>
374
+ <p style="color: #888; font-size: 0.85rem;">Relevance: {source['relevance_score']:.1%}</p>
375
+ </div>
376
+ """, unsafe_allow_html=True)
377
+
378
+ # Tab 2: Metrics with PLOTS (unchanged)
379
  with tab2:
380
+ st.markdown("### πŸ“Š THE RECEIPTS - System Performance")
381
+
382
+ from metrics_tracker import MetricsTracker
383
+
 
 
 
384
  tracker = MetricsTracker()
385
+
386
+ days = st.selectbox("Time Period", [1, 7, 30], index=1)
387
  report = tracker.generate_report(days=days)
388
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  col1, col2 = st.columns(2)
390
+
391
  with col1:
392
+ st.markdown('<div class="plot-container">', unsafe_allow_html=True)
393
+ st.markdown("#### πŸ“ˆ Query Stats")
394
+
395
+ fig = go.Figure()
396
+ fig.add_trace(go.Indicator(
397
+ mode="number+delta",
398
+ value=report['overview']['total_queries'],
399
+ title="Total Queries",
400
+ delta={'reference': report['overview']['total_queries'] * 0.8}
401
+ ))
402
+ fig.update_layout(height=200, paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', font_color='white')
403
+ st.plotly_chart(fig, use_container_width=True)
404
+ st.markdown('</div>', unsafe_allow_html=True)
405
+
406
+ st.markdown('<div class="plot-container">', unsafe_allow_html=True)
407
+ st.markdown("#### ⚑ Latency")
408
  latency = report['performance']['latency']
409
+
410
+ fig = go.Figure(go.Bar(
411
+ x=['Avg', 'P95', 'P99'],
412
+ y=[latency['avg_ms'], latency['p95_ms'], latency['p99_ms']],
413
+ marker_color=['#ff1744', '#f50057', '#8b0000']
414
+ ))
415
+ fig.update_layout(height=250, paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', font_color='white')
 
 
 
 
 
 
 
416
  st.plotly_chart(fig, use_container_width=True)
417
+ st.markdown('</div>', unsafe_allow_html=True)
418
+
419
  with col2:
420
+ st.markdown('<div class="plot-container">', unsafe_allow_html=True)
421
+ st.markdown("#### 😊 Satisfaction")
422
+
423
+ sat_rate = report['performance']['satisfaction_rate']
424
+ fig = go.Figure(go.Indicator(
425
+ mode="gauge+number+delta",
426
+ value=sat_rate * 100,
427
+ title="Satisfaction %",
428
+ domain={'x': [0, 1], 'y': [0, 1]},
429
+ gauge={'axis': {'range': [0, 100]},
430
+ 'bar': {'color': "#ff1744"},
431
+ 'steps': [
432
+ {'range': [0, 50], 'color': "#8b0000"},
433
+ {'range': [50, 75], 'color': "#dc143c"}
434
+ ]}
435
+ ))
436
+ fig.update_layout(height=250, paper_bgcolor='rgba(0,0,0,0)', font_color='white')
437
  st.plotly_chart(fig, use_container_width=True)
438
+ st.markdown('</div>', unsafe_allow_html=True)
439
+
440
+ st.markdown('<div class="plot-container">', unsafe_allow_html=True)
441
+ st.markdown("#### πŸ’° Cost")
442
+ st.metric("Estimated Cost", f"${report['costs']['estimated_cost_usd']:.4f}")
443
+ st.metric("Per Query", f"${report['costs']['cost_per_query']:.6f}")
444
+ st.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
445
 
446
+ # Tab 3: About (unchanged)
447
  with tab3:
448
+ st.markdown("### About CineRAG")
449
+
450
  col1, col2 = st.columns(2)
451
+
452
  with col1:
453
  st.markdown("""
454
+ **🍿 What's This?**
455
+ Your gossip source for cinema secrets:
456
+ - 🎬 Behind-the-scenes drama
457
+ - 🀫 Production secrets
458
+ - πŸ’° Budget controversies
459
+ - 🎭 Casting tea
460
+ **πŸ”§ Tech:**
461
+ - Hybrid Search (BM25 + Semantic)
462
+ - Groq AI (Mixtral-8x7b)
463
+ - 85.7% accuracy
464
+ - <1s response time
 
 
 
 
465
  """)
466
+
467
  with col2:
 
 
468
  st.markdown("""
469
+ **πŸ“Š The Numbers:**
470
+ - 466 movies
471
+ - 252 with secrets
472
+ - 3,000+ facts
473
+ - Real-time AI
474
+ **πŸ‘©β€πŸ’» Built By:**
475
+ **Rima Alaya**
476
+ AI/ML Engineer
 
 
 
 
477
  [GitHub](https://github.com/RimaAlaya) | [LinkedIn](https://linkedin.com/in/rima-alaya)
478
  """)
479
 
480
+ # Footer
481
  st.markdown("---")
482
+ st.markdown("""
483
+ <div style="text-align: center; padding: 20px;">
484
+ <p style="color: #888;">🍿 Spilling cinema tea since 2025 | Built with ❀️ and β˜•</p>
485
+ </div>
486
+ """, unsafe_allow_html=True)