VyLala commited on
Commit
7922f77
·
verified ·
1 Parent(s): 3ebb0b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -41
app.py CHANGED
@@ -46,7 +46,7 @@ custom_css = """
46
  width: 100%; height: 100%;
47
  background: rgba(0,0,0,0.6);
48
  z-index: 9999;
49
- display: none; /* Hidden by default */
50
  flex-direction: column;
51
  justify-content: center;
52
  align-items: center;
@@ -74,15 +74,23 @@ custom_css = """
74
  #nps-close:hover {
75
  color: black;
76
  }
77
- #nps-box button:active {
78
- transform: scale(0.95);
79
- background-color: #ddd;
 
 
 
 
 
 
 
 
80
  }
81
-
82
  """
83
 
84
 
85
 
 
86
  with gr.Blocks() as interface:
87
  # with gr.Tab("CURIOUS ABOUT THIS PRODUCT?"):
88
  # gr.HTML(value=pricing_html)
@@ -146,6 +154,7 @@ with gr.Blocks() as interface:
146
 
147
  selected_score = gr.Textbox(label="selected_score", visible=False)
148
  nps_submit = gr.Button("Submit")
 
149
 
150
 
151
  with gr.Group(visible=False) as results_group:
@@ -396,7 +405,7 @@ with gr.Blocks() as interface:
396
  # "\n".join(log_lines)
397
  # )
398
  def submit_nps(email,nps_score):
399
- if nps_score is None:
400
  return "❌ Please select a score before submitting."
401
  log_submission_to_gsheet(email, [], nps_score)
402
  return "✅ Thanks for submitting your feedback!"
@@ -1189,11 +1198,8 @@ with gr.Blocks() as interface:
1189
  inputs=[raw_text, q1, q2, contact],
1190
  outputs=[feedback_status]
1191
  )
1192
- nps_message = gr.Markdown(visible=True)
1193
- #nps_button.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=nps_output)
1194
  nps_submit.click(fn=submit_nps, inputs=[user_email, selected_score], outputs=[nps_message])
1195
- #nps_close.click(fn=lambda: gr.update(visible=False), outputs=[nps_modal])
1196
-
1197
 
1198
  gr.HTML("""
1199
  <style>
@@ -1279,42 +1285,35 @@ with gr.Blocks() as interface:
1279
  with gr.Tab("PRICING"):
1280
  gr.HTML(value=pricing_html)
1281
 
1282
- interface.load(js="""
1283
- () => {
1284
- // Close button functionality
1285
- const closeBtn = document.getElementById('nps-close');
1286
- if (closeBtn) {
1287
- closeBtn.addEventListener('click', () => {
1288
  const overlay = document.getElementById('nps-overlay');
1289
- if (overlay) overlay.style.display = 'none';
1290
- });
1291
- }
1292
-
1293
- // Handle score button clicks
1294
- document.querySelectorAll('.nps-btn').forEach(btn => {
1295
- btn.addEventListener('click', () => {
1296
- const score = btn.getAttribute('data-score');
1297
  const hiddenInput = document.querySelector('textarea[aria-label="selected_score"]');
1298
- if (hiddenInput) {
1299
- hiddenInput.value = score;
1300
- hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
 
 
1301
  }
1302
- });
1303
- });
1304
 
1305
- const submitBtn = document.querySelector('button:has-text("Submit")');
1306
- if (submitBtn) {
1307
- submitBtn.addEventListener('click', () => {
1308
- submitBtn.style.border = '2px solid green';
1309
- submitBtn.style.backgroundColor = '#e6ffe6';
1310
- setTimeout(() => {
1311
- submitBtn.style.border = '';
1312
- submitBtn.style.backgroundColor = '';
1313
- }, 300); // reset after 0.3s
1314
- });
 
1315
  }
1316
- }
1317
- """)
1318
 
1319
 
1320
 
 
46
  width: 100%; height: 100%;
47
  background: rgba(0,0,0,0.6);
48
  z-index: 9999;
49
+ display: none;
50
  flex-direction: column;
51
  justify-content: center;
52
  align-items: center;
 
74
  #nps-close:hover {
75
  color: black;
76
  }
77
+ .nps-btn {
78
+ border: 1px solid #ccc;
79
+ background: #f9f9f9;
80
+ padding: 6px 10px;
81
+ cursor: pointer;
82
+ border-radius: 6px;
83
+ }
84
+ .nps-btn.selected {
85
+ background: #007bff;
86
+ color: white;
87
+ border-color: #007bff;
88
  }
 
89
  """
90
 
91
 
92
 
93
+
94
  with gr.Blocks() as interface:
95
  # with gr.Tab("CURIOUS ABOUT THIS PRODUCT?"):
96
  # gr.HTML(value=pricing_html)
 
154
 
155
  selected_score = gr.Textbox(label="selected_score", visible=False)
156
  nps_submit = gr.Button("Submit")
157
+ nps_message = gr.Markdown(visible=True)
158
 
159
 
160
  with gr.Group(visible=False) as results_group:
 
405
  # "\n".join(log_lines)
406
  # )
407
  def submit_nps(email,nps_score):
408
+ if not nps_score.strip():
409
  return "❌ Please select a score before submitting."
410
  log_submission_to_gsheet(email, [], nps_score)
411
  return "✅ Thanks for submitting your feedback!"
 
1198
  inputs=[raw_text, q1, q2, contact],
1199
  outputs=[feedback_status]
1200
  )
 
 
1201
  nps_submit.click(fn=submit_nps, inputs=[user_email, selected_score], outputs=[nps_message])
1202
+
 
1203
 
1204
  gr.HTML("""
1205
  <style>
 
1285
  with gr.Tab("PRICING"):
1286
  gr.HTML(value=pricing_html)
1287
 
1288
+ interface.load(
1289
+ js="""
1290
+ () => {
1291
+ setTimeout(() => {
 
 
1292
  const overlay = document.getElementById('nps-overlay');
1293
+ const closeBtn = document.getElementById('nps-close');
1294
+ const buttons = document.querySelectorAll('.nps-btn');
 
 
 
 
 
 
1295
  const hiddenInput = document.querySelector('textarea[aria-label="selected_score"]');
1296
+
1297
+ if (closeBtn) {
1298
+ closeBtn.onclick = () => {
1299
+ overlay.style.display = 'none';
1300
+ };
1301
  }
 
 
1302
 
1303
+ buttons.forEach(btn => {
1304
+ btn.onclick = () => {
1305
+ buttons.forEach(b => b.classList.remove('selected'));
1306
+ btn.classList.add('selected');
1307
+ if (hiddenInput) {
1308
+ hiddenInput.value = btn.getAttribute('data-score');
1309
+ hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
1310
+ }
1311
+ };
1312
+ });
1313
+ }, 500);
1314
  }
1315
+ """
1316
+ )
1317
 
1318
 
1319