ghostai1 commited on
Commit
8e18840
·
verified ·
1 Parent(s): 6986bb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -29
app.py CHANGED
@@ -142,7 +142,7 @@ def plot_metrics(metrics):
142
  return 'rag_plot.png'
143
 
144
  # Gradio interface with stacked buttons and single output
145
- def chat_interface(query, response_output, faq_output, cleanup_output, plot_output):
146
  try:
147
  response, retrieved_faqs, metrics = rag_process(query)
148
  plot_path = plot_metrics(metrics)
@@ -186,9 +186,11 @@ body {
186
  border-radius: 5px;
187
  padding: 10px 20px;
188
  margin: 5px 0;
189
- width: 100%;
 
190
  text-align: center;
191
  transition: background 0.3s ease;
 
192
  }
193
  .gr-button:hover {
194
  background: #1c86ee;
@@ -200,9 +202,10 @@ body {
200
  border: 1px solid #4a4a4a;
201
  border-radius: 5px;
202
  margin-bottom: 10px;
 
203
  }
204
  #app-container {
205
- max-width: 600px;
206
  width: 100%;
207
  padding: 20px;
208
  background: #252525;
@@ -217,17 +220,25 @@ body {
217
  background: #303030;
218
  border-radius: 8px;
219
  margin-bottom: 20px;
 
 
220
  }
221
  #output-container {
222
  background: #303030;
223
  padding: 15px;
224
  border-radius: 8px;
225
  margin-top: 20px;
 
226
  }
227
  .text-center {
228
  text-align: center;
229
  margin-bottom: 20px;
230
  }
 
 
 
 
 
231
  """
232
 
233
  # Get unique questions for buttons (after cleanup)
@@ -238,31 +249,42 @@ with gr.Blocks(css=custom_css) as demo:
238
  gr.Markdown("# Customer Experience Bot Demo", elem_classes="text-center")
239
  gr.Markdown("Select a question to see the bot's response, retrieved FAQs, and call center data cleanup stats.", elem_classes="text-center")
240
 
241
- # Single output panel (defined once)
242
- with gr.Column(elem_id="output-container"):
243
- response_output = gr.Textbox(label="Bot Response")
244
- faq_output = gr.Textbox(label="Retrieved FAQs")
245
- cleanup_output = gr.Textbox(label="Data Cleanup Stats")
246
- plot_output = gr.Image(label="RAG Pipeline Metrics")
247
-
248
- # Stacked buttons in a single column
249
- with gr.Column(elem_id="button-container"):
250
- for question in unique_questions:
251
- gr.Button(question).click(
252
- fn=chat_interface,
253
- inputs=[
254
- gr.State(value=question),
255
- response_output,
256
- faq_output,
257
- cleanup_output,
258
- plot_output
259
- ],
260
- outputs=[
261
- response_output,
262
- faq_output,
263
- cleanup_output,
264
- plot_output
265
- ]
266
- )
 
 
 
 
 
 
 
 
 
 
 
267
 
268
  demo.launch()
 
142
  return 'rag_plot.png'
143
 
144
  # Gradio interface with stacked buttons and single output
145
+ def chat_interface(query):
146
  try:
147
  response, retrieved_faqs, metrics = rag_process(query)
148
  plot_path = plot_metrics(metrics)
 
186
  border-radius: 5px;
187
  padding: 10px 20px;
188
  margin: 5px 0;
189
+ width: 80%;
190
+ align-self: center;
191
  text-align: center;
192
  transition: background 0.3s ease;
193
+ font-size: 16px;
194
  }
195
  .gr-button:hover {
196
  background: #1c86ee;
 
202
  border: 1px solid #4a4a4a;
203
  border-radius: 5px;
204
  margin-bottom: 10px;
205
+ font-size: 14px;
206
  }
207
  #app-container {
208
+ max-width: 800px;
209
  width: 100%;
210
  padding: 20px;
211
  background: #252525;
 
220
  background: #303030;
221
  border-radius: 8px;
222
  margin-bottom: 20px;
223
+ align-items: center;
224
+ width: 66%;
225
  }
226
  #output-container {
227
  background: #303030;
228
  padding: 15px;
229
  border-radius: 8px;
230
  margin-top: 20px;
231
+ width: 100%;
232
  }
233
  .text-center {
234
  text-align: center;
235
  margin-bottom: 20px;
236
  }
237
+ #app-row {
238
+ display: flex;
239
+ gap: 20px;
240
+ justify-content: space-between;
241
+ }
242
  """
243
 
244
  # Get unique questions for buttons (after cleanup)
 
249
  gr.Markdown("# Customer Experience Bot Demo", elem_classes="text-center")
250
  gr.Markdown("Select a question to see the bot's response, retrieved FAQs, and call center data cleanup stats.", elem_classes="text-center")
251
 
252
+ # Rule of thirds layout: buttons on left 2/3, outputs on right 1/3
253
+ with gr.Row(elem_id="app-row"):
254
+ # Buttons (left 2/3)
255
+ with gr.Column(elem_id="button-container"):
256
+ for question in unique_questions:
257
+ gr.Button(question).click(
258
+ fn=chat_interface,
259
+ inputs=gr.State(value=question),
260
+ outputs=[
261
+ gr.State(),
262
+ gr.State(),
263
+ gr.State(),
264
+ gr.State()
265
+ ],
266
+ _js="() => {return [arguments[0], document.querySelector('#response-output').value, document.querySelector('#faq-output').value, document.querySelector('#cleanup-output').value, document.querySelector('#plot-output').value]}"
267
+ ).then(
268
+ fn=lambda response, faq_text, cleanup_stats, plot_path: (response, faq_text, cleanup_stats, plot_path),
269
+ inputs=[
270
+ gr.State(),
271
+ gr.State(),
272
+ gr.State(),
273
+ gr.State()
274
+ ],
275
+ outputs=[
276
+ gr.Textbox(label="Bot Response", elem_id="response-output"),
277
+ gr.Textbox(label="Retrieved FAQs", elem_id="faq-output"),
278
+ gr.Textbox(label="Data Cleanup Stats", elem_id="cleanup-output"),
279
+ gr.Image(label="RAG Pipeline Metrics", elem_id="plot-output")
280
+ ]
281
+ )
282
+
283
+ # Single output panel (right 1/3)
284
+ with gr.Column(elem_id="output-container"):
285
+ response_output = gr.Textbox(label="Bot Response", elem_id="response-output")
286
+ faq_output = gr.Textbox(label="Retrieved FAQs", elem_id="faq-output")
287
+ cleanup_output = gr.Textbox(label="Data Cleanup Stats", elem_id="cleanup-output")
288
+ plot_output = gr.Image(label="RAG Pipeline Metrics", elem_id="plot-output")
289
 
290
  demo.launch()