ydshieh HF Staff commited on
Commit
985874c
·
verified ·
1 Parent(s): 571875d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -65
app.py CHANGED
@@ -224,74 +224,24 @@ with gr.Blocks() as demo:
224
  json_view = gr.Code(label="Latest entry details", language="json")
225
  status = gr.Markdown("")
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  search_btn.click(query, inputs=[repo_box, pr_box, sha_box], outputs=[table, json_view, status])
228
  refresh_btn.click(refresh_dataset, outputs=status)
229
 
230
- # Add JavaScript that runs after Gradio initializes and directly manipulates the components
231
- gr.HTML("""
232
- <script>
233
- // Wait for Gradio to fully load
234
- function populateFromURL() {
235
- const params = new URLSearchParams(window.location.search);
236
- const repo = params.get('repo') || '';
237
- const pr = params.get('pr') || '';
238
- const sha = params.get('sha') || '';
239
-
240
- console.log('Attempting to populate with:', {repo, pr, sha});
241
-
242
- if (!repo && !pr && !sha) {
243
- console.log('No URL parameters found');
244
- return;
245
- }
246
-
247
- // Try multiple selectors to find the inputs
248
- const allInputs = document.querySelectorAll('input[type="text"], textarea');
249
- console.log('Found ' + allInputs.length + ' input elements');
250
-
251
- // Look for inputs by their labels
252
- const labels = document.querySelectorAll('label');
253
- labels.forEach(label => {
254
- const text = label.textContent;
255
- const input = label.parentElement?.querySelector('input, textarea');
256
-
257
- if (text.includes('Repository') && repo && input) {
258
- console.log('Setting repository to:', repo);
259
- input.value = repo;
260
- input.dispatchEvent(new Event('input', {bubbles: true}));
261
- input.dispatchEvent(new Event('change', {bubbles: true}));
262
- } else if (text.includes('PR number') && pr && input) {
263
- console.log('Setting PR to:', pr);
264
- input.value = pr;
265
- input.dispatchEvent(new Event('input', {bubbles: true}));
266
- input.dispatchEvent(new Event('change', {bubbles: true}));
267
- } else if (text.includes('Commit SHA') && sha && input) {
268
- console.log('Setting SHA to:', sha);
269
- input.value = sha;
270
- input.dispatchEvent(new Event('input', {bubbles: true}));
271
- input.dispatchEvent(new Event('change', {bubbles: true}));
272
- }
273
- });
274
-
275
- // Auto-trigger search if we have a PR
276
- if (pr) {
277
- setTimeout(() => {
278
- const buttons = document.querySelectorAll('button');
279
- buttons.forEach(btn => {
280
- if (btn.textContent.includes('Search')) {
281
- console.log('Auto-clicking Search button');
282
- btn.click();
283
- }
284
- });
285
- }, 1000);
286
- }
287
- }
288
-
289
- // Try multiple times as Gradio might take time to initialize
290
- setTimeout(populateFromURL, 500);
291
- setTimeout(populateFromURL, 1500);
292
- setTimeout(populateFromURL, 3000);
293
- </script>
294
- """)
295
 
296
  if __name__ == "__main__":
297
  demo.queue(max_size=20).launch(ssr_mode=False)
 
224
  json_view = gr.Code(label="Latest entry details", language="json")
225
  status = gr.Markdown("")
226
 
227
+ def get_url_params(request: gr.Request):
228
+ """Get URL parameters from the request"""
229
+ try:
230
+ params = dict(request.query_params)
231
+ repo = params.get('repo', '')
232
+ pr = params.get('pr', '')
233
+ sha = params.get('sha', '')
234
+ print(f"DEBUG: URL params from request: repo={repo}, pr={pr}, sha={sha}")
235
+ return repo, pr, sha
236
+ except Exception as e:
237
+ print(f"DEBUG: Error getting URL params: {e}")
238
+ return '', '', ''
239
+
240
  search_btn.click(query, inputs=[repo_box, pr_box, sha_box], outputs=[table, json_view, status])
241
  refresh_btn.click(refresh_dataset, outputs=status)
242
 
243
+ # Load URL parameters when page loads
244
+ demo.load(get_url_params, outputs=[repo_box, pr_box, sha_box])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
  if __name__ == "__main__":
247
  demo.queue(max_size=20).launch(ssr_mode=False)