VyLala commited on
Commit
66b887b
·
verified ·
1 Parent(s): c1d85a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -10
app.py CHANGED
@@ -118,12 +118,56 @@ with gr.Blocks() as interface:
118
  # with gr.Row():
119
  # nps_submit = gr.Button("Submit")
120
  # nps_close = gr.Button("X", elem_id="nps-close")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  with gr.Group(visible=False, elem_id="nps-overlay") as nps_modal:
122
- with gr.Column(elem_id="nps-box"):
123
- gr.HTML('<span id="nps-close">✕</span>') # Close button
124
  gr.Markdown("### How likely are you to recommend this tool to a colleague or peer?")
125
- nps_slider = gr.Slider(minimum=0, maximum=10, step=1, label="Your NPS Score (0-10)")
 
126
  nps_submit = gr.Button("Submit")
 
127
 
128
  with gr.Group(visible=False) as results_group:
129
  # with gr.Accordion("Open to See the Result", open=False) as results:
@@ -1160,9 +1204,9 @@ with gr.Blocks() as interface:
1160
  inputs=[raw_text, q1, q2, contact],
1161
  outputs=[feedback_status]
1162
  )
1163
-
1164
  #nps_button.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=nps_output)
1165
- nps_submit.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=[])
1166
  #nps_close.click(fn=lambda: gr.update(visible=False), outputs=[nps_modal])
1167
 
1168
 
@@ -1250,13 +1294,39 @@ with gr.Blocks() as interface:
1250
  with gr.Tab("PRICING"):
1251
  gr.HTML(value=pricing_html)
1252
  interface.load(js="""
1253
- () => {
1254
- // Close button
1255
- document.getElementById('nps-close').onclick = function() {
1256
- document.getElementById('nps-overlay').style.display = 'none';
1257
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258
  }
 
1259
  """)
1260
 
1261
 
 
 
1262
  interface.launch(share=True,debug=True)
 
118
  # with gr.Row():
119
  # nps_submit = gr.Button("Submit")
120
  # nps_close = gr.Button("X", elem_id="nps-close")
121
+ nps_html = """
122
+ <div id="nps-container" style="text-align:center;">
123
+ <style>
124
+ .nps-btn {
125
+ display: inline-block;
126
+ width: 40px;
127
+ height: 40px;
128
+ line-height: 40px;
129
+ margin: 4px;
130
+ border-radius: 6px;
131
+ color: white;
132
+ font-weight: bold;
133
+ cursor: pointer;
134
+ user-select: none;
135
+ }
136
+ .nps-red { background-color: #d9534f; }
137
+ .nps-yellow { background-color: #f0ad4e; }
138
+ .nps-green { background-color: #5cb85c; }
139
+ .nps-btn:hover { opacity: 0.8; }
140
+ #nps-labels { margin-top: 8px; font-size: 14px; color: #555; }
141
+ </style>
142
+ <div>
143
+ <span class="nps-btn nps-red" data-score="0">0</span>
144
+ <span class="nps-btn nps-red" data-score="1">1</span>
145
+ <span class="nps-btn nps-red" data-score="2">2</span>
146
+ <span class="nps-btn nps-red" data-score="3">3</span>
147
+ <span class="nps-btn nps-red" data-score="4">4</span>
148
+ <span class="nps-btn nps-red" data-score="5">5</span>
149
+ <span class="nps-btn nps-red" data-score="6">6</span>
150
+ <span class="nps-btn nps-yellow" data-score="7">7</span>
151
+ <span class="nps-btn nps-yellow" data-score="8">8</span>
152
+ <span class="nps-btn nps-green" data-score="9">9</span>
153
+ <span class="nps-btn nps-green" data-score="10">10</span>
154
+ </div>
155
+ <div id="nps-labels">
156
+ <span style="float:left;">Not at all likely</span>
157
+ <span>Neutral</span>
158
+ <span style="float:right;">Extremely likely</span>
159
+ </div>
160
+ </div>
161
+ """
162
+
163
  with gr.Group(visible=False, elem_id="nps-overlay") as nps_modal:
164
+ with gr.Column(elem_id="nps-box", interactive=True):
165
+ gr.HTML('<span id="nps-close">✕</span>')
166
  gr.Markdown("### How likely are you to recommend this tool to a colleague or peer?")
167
+ nps_html_component = gr.HTML(nps_html)
168
+ selected_score = gr.Textbox(label="Selected NPS Score", visible=False)
169
  nps_submit = gr.Button("Submit")
170
+
171
 
172
  with gr.Group(visible=False) as results_group:
173
  # with gr.Accordion("Open to See the Result", open=False) as results:
 
1204
  inputs=[raw_text, q1, q2, contact],
1205
  outputs=[feedback_status]
1206
  )
1207
+ nps_message = gr.Markdown(visible=True)
1208
  #nps_button.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=nps_output)
1209
+ nps_submit.click(fn=submit_nps, inputs=[user_email, selected_score], outputs=[nps_message])
1210
  #nps_close.click(fn=lambda: gr.update(visible=False), outputs=[nps_modal])
1211
 
1212
 
 
1294
  with gr.Tab("PRICING"):
1295
  gr.HTML(value=pricing_html)
1296
  interface.load(js="""
1297
+ () => {
1298
+ // Close modal
1299
+ document.getElementById('nps-close').onclick = function() {
1300
+ document.getElementById('nps-overlay').style.display = 'none';
1301
+ };
1302
+
1303
+ // NPS number clicks
1304
+ document.querySelectorAll('#nps-container .nps-btn').forEach(btn => {
1305
+ btn.addEventListener('click', function() {
1306
+ const score = this.getAttribute('data-score');
1307
+ const input = document.querySelector('textarea[aria-label="Selected NPS Score"]');
1308
+ if (input) {
1309
+ input.value = score;
1310
+ input.dispatchEvent(new Event('input', { bubbles: true }));
1311
+ }
1312
+ });
1313
+ });
1314
+
1315
+ const submitBtn = document.querySelector('button:has-text("Submit")');
1316
+ if (submitBtn) {
1317
+ submitBtn.addEventListener('click', () => {
1318
+ submitBtn.style.border = '2px solid green';
1319
+ submitBtn.style.backgroundColor = '#e6ffe6';
1320
+ setTimeout(() => {
1321
+ submitBtn.style.border = '';
1322
+ submitBtn.style.backgroundColor = '';
1323
+ }, 300); // reset after 0.3s
1324
+ });
1325
  }
1326
+ }
1327
  """)
1328
 
1329
 
1330
+
1331
+
1332
  interface.launch(share=True,debug=True)