SiddharthAK commited on
Commit
9a12ea3
Β·
verified Β·
1 Parent(s): 80f5ef5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -8
app.py CHANGED
@@ -6,12 +6,34 @@ from tqdm.auto import tqdm
6
  import os
7
 
8
 
9
- # Remove or comment out any CSS related to .share-button if you want Gradio to handle its default placement.
10
- # If you *still* want it fixed to a specific corner globally, you can uncomment your original fixed CSS.
11
  css = """
12
- /* No specific CSS for .share-button if we're letting Gradio place it dynamically
13
- when demo.launch(share=True) is used.
14
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  """
16
 
17
 
@@ -414,6 +436,10 @@ def calculate_dot_product_and_representations_independent(query_model_choice, do
414
  return full_output
415
 
416
 
 
 
 
 
417
  # --- Gradio Interface Setup with Tabs ---
418
  with gr.Blocks(title="SPLADE Demos", css=css) as demo:
419
  gr.Markdown("# 🌌 Sparse Encoder Playground") # Updated title
@@ -438,11 +464,25 @@ with gr.Blocks(title="SPLADE Demos", css=css) as demo:
438
  label="Enter your query or document text here:",
439
  placeholder="e.g., Why is Padua the nicest city in Italy?"
440
  )
441
- # Removed gr.ShareButton here as it caused an AttributeError
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  info_output_display = gr.Markdown(
443
  value="",
444
  label="Vector Information",
445
- elem_id="info_output_display" # Add an ID for potential CSS if needed
446
  )
447
  with gr.Column(scale=2): # Right column for the main representation output
448
  main_representation_output = gr.Markdown()
@@ -458,10 +498,19 @@ with gr.Blocks(title="SPLADE Demos", css=css) as demo:
458
  inputs=[model_radio, input_text],
459
  outputs=[main_representation_output, info_output_display]
460
  )
 
 
 
 
 
 
 
 
 
461
 
462
  # Initial call to populate on load (optional, but good for demo)
463
  demo.load(
464
- fn=lambda: predict_representation_explorer(model_radio.value, input_text.value),
465
  outputs=[main_representation_output, info_output_display]
466
  )
467
 
 
6
  import os
7
 
8
 
9
+ # CSS to style the share button
 
10
  css = """
11
+ .share-button-container {
12
+ display: flex;
13
+ justify-content: center;
14
+ margin-top: 10px;
15
+ margin-bottom: 20px;
16
+ }
17
+
18
+ .custom-share-button {
19
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
20
+ border: none;
21
+ color: white;
22
+ padding: 8px 16px;
23
+ text-align: center;
24
+ text-decoration: none;
25
+ display: inline-block;
26
+ font-size: 14px;
27
+ margin: 4px 2px;
28
+ cursor: pointer;
29
+ border-radius: 6px;
30
+ transition: all 0.3s ease;
31
+ }
32
+
33
+ .custom-share-button:hover {
34
+ transform: translateY(-2px);
35
+ box-shadow: 0 4px 8px rgba(0,0,0,0.2);
36
+ }
37
  """
38
 
39
 
 
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:
445
  gr.Markdown("# 🌌 Sparse Encoder Playground") # Updated title
 
464
  label="Enter your query or document text here:",
465
  placeholder="e.g., Why is Padua the nicest city in Italy?"
466
  )
467
+
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(
483
  value="",
484
  label="Vector Information",
485
+ elem_id="info_output_display"
486
  )
487
  with gr.Column(scale=2): # Right column for the main representation output
488
  main_representation_output = gr.Markdown()
 
498
  inputs=[model_radio, input_text],
499
  outputs=[main_representation_output, info_output_display]
500
  )
501
+
502
+ # Connect share button
503
+ share_button.click(
504
+ fn=generate_share_link,
505
+ outputs=share_output
506
+ ).then(
507
+ fn=lambda: gr.update(visible=True),
508
+ outputs=share_output
509
+ )
510
 
511
  # Initial call to populate on load (optional, but good for demo)
512
  demo.load(
513
+ fn=lambda: predict_representation_explorer("MLM encoder (SPLADE-cocondenser-distil)", ""),
514
  outputs=[main_representation_output, info_output_display]
515
  )
516