SiddharthAK commited on
Commit
945e73b
Β·
verified Β·
1 Parent(s): 9a12ea3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -9
app.py CHANGED
@@ -436,9 +436,22 @@ def calculate_dot_product_and_representations_independent(query_model_choice, do
436
  return full_output
437
 
438
 
439
- # Function to generate share link (simulated)
440
- def generate_share_link():
441
- return "πŸ”— Share link functionality would be available when running with share=True"
 
 
 
 
 
 
 
 
 
 
 
 
 
442
 
443
  # --- Gradio Interface Setup with Tabs ---
444
  with gr.Blocks(title="SPLADE Demos", css=css) as demo:
@@ -468,15 +481,16 @@ with gr.Blocks(title="SPLADE Demos", css=css) as demo:
468
  # Add share button underneath the input field
469
  with gr.Row(elem_classes="share-button-container"):
470
  share_button = gr.Button(
471
- "πŸ“€ Generate Share Link",
472
  elem_classes="custom-share-button",
473
  size="sm"
474
  )
475
 
476
- share_output = gr.Textbox(
477
  label="Share Link",
478
- interactive=False,
479
- visible=False
 
480
  )
481
 
482
  info_output_display = gr.Markdown(
@@ -487,6 +501,16 @@ with gr.Blocks(title="SPLADE Demos", css=css) as demo:
487
  with gr.Column(scale=2): # Right column for the main representation output
488
  main_representation_output = gr.Markdown()
489
 
 
 
 
 
 
 
 
 
 
 
490
  # Connect the interface elements
491
  model_radio.change(
492
  fn=predict_representation_explorer,
@@ -552,5 +576,12 @@ with gr.Blocks(title="SPLADE Demos", css=css) as demo:
552
  allow_flagging="never" # Keep this to keep the share button at the bottom of THIS interface
553
  )
554
 
555
- # Crucial step: Launch the demo with share=True
556
- demo.launch(share=True)
 
 
 
 
 
 
 
 
436
  return full_output
437
 
438
 
439
+ # Function to get the share URL (will be populated when demo launches)
440
+ share_url = None
441
+
442
+ def get_share_url():
443
+ global share_url
444
+ if share_url:
445
+ return f"πŸ”— Share this app: {share_url}"
446
+ else:
447
+ return "πŸ”— Share URL will be available after launching with share=True"
448
+
449
+ def copy_share_url():
450
+ global share_url
451
+ if share_url:
452
+ return share_url
453
+ else:
454
+ return "Share URL not available yet"
455
 
456
  # --- Gradio Interface Setup with Tabs ---
457
  with gr.Blocks(title="SPLADE Demos", css=css) as demo:
 
481
  # Add share button underneath the input field
482
  with gr.Row(elem_classes="share-button-container"):
483
  share_button = gr.Button(
484
+ "πŸ”— Get Share Link",
485
  elem_classes="custom-share-button",
486
  size="sm"
487
  )
488
 
489
+ share_display = gr.Textbox(
490
  label="Share Link",
491
+ interactive=True,
492
+ visible=False,
493
+ placeholder="Share URL will appear here..."
494
  )
495
 
496
  info_output_display = gr.Markdown(
 
501
  with gr.Column(scale=2): # Right column for the main representation output
502
  main_representation_output = gr.Markdown()
503
 
504
+
505
+ # Connect share button
506
+ share_button.click(
507
+ fn=copy_share_url,
508
+ outputs=share_display
509
+ ).then(
510
+ fn=lambda: gr.update(visible=True),
511
+ outputs=share_display
512
+ )
513
+
514
  # Connect the interface elements
515
  model_radio.change(
516
  fn=predict_representation_explorer,
 
576
  allow_flagging="never" # Keep this to keep the share button at the bottom of THIS interface
577
  )
578
 
579
+ # Crucial step: Launch the demo with share=True and capture the share URL
580
+ if __name__ == "__main__":
581
+ # Launch and capture the share URL
582
+ demo_info = demo.launch(share=True, return_url=True)
583
+ if hasattr(demo_info, 'share_url') and demo_info.share_url:
584
+ share_url = demo_info.share_url
585
+ print(f"Share URL: {share_url}")
586
+ else:
587
+ print("Share URL not available")