SiddharthAK commited on
Commit
d357027
·
verified ·
1 Parent(s): c138ed8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -21
app.py CHANGED
@@ -391,6 +391,10 @@ def format_sparse_vector_output(splade_vector, tokenizer, is_binary=False):
391
  else:
392
  terms_list = []
393
  for i, (term, weight) in enumerate(sorted_representation):
 
 
 
 
394
  if is_binary:
395
  terms_list.append(f"**{term}**")
396
  else:
@@ -552,31 +556,47 @@ with gr.Blocks(title="SPLADE Demos", css=css) as demo:
552
  "Binary Bag-of-Words"
553
  ]
554
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  gr.Interface(
556
  fn=calculate_dot_product_and_representations_independent,
557
  inputs=[
558
- gr.Radio(
559
- model_choices,
560
- label="Choose Query Encoding Model",
561
- value="MLM encoder (SPLADE-cocondenser-distil)"
562
- ),
563
- gr.Radio(
564
- model_choices,
565
- label="Choose Document Encoding Model",
566
- value="MLM encoder (SPLADE-cocondenser-distil)"
567
- ),
568
- gr.Textbox(
569
- lines=3,
570
- label="Enter Query Text:",
571
- placeholder="e.g., famous dishes of Padua"
572
- ),
573
- gr.Textbox(
574
- lines=5,
575
- label="Enter Document Text:",
576
- placeholder="e.g., Padua's cuisine is as famous as its legendary University."
577
- )
578
  ],
579
- outputs=gr.Markdown(),
580
  allow_flagging="never"
581
  )
582
 
 
391
  else:
392
  terms_list = []
393
  for i, (term, weight) in enumerate(sorted_representation):
394
+ # Limiting to 50 terms for display to avoid overly long output
395
+ if i >= 50:
396
+ terms_list.append(f"...and {len(sorted_representation) - 50} more terms.")
397
+ break
398
  if is_binary:
399
  terms_list.append(f"**{term}**")
400
  else:
 
556
  "Binary Bag-of-Words"
557
  ]
558
 
559
+ # Input components for the second tab
560
+ query_model_radio = gr.Radio(
561
+ model_choices,
562
+ label="Choose Query Encoding Model",
563
+ value="MLM encoder (SPLADE-cocondenser-distil)"
564
+ )
565
+ doc_model_radio = gr.Radio(
566
+ model_choices,
567
+ label="Choose Document Encoding Model",
568
+ value="MLM encoder (SPLADE-cocondenser-distil)"
569
+ )
570
+ query_text_input = gr.Textbox(
571
+ lines=3,
572
+ label="Enter Query Text:",
573
+ placeholder="e.g., famous dishes of Padua"
574
+ )
575
+ doc_text_input = gr.Textbox(
576
+ lines=5,
577
+ label="Enter Document Text:",
578
+ placeholder="e.g., Padua's cuisine is as famous as its legendary University."
579
+ )
580
+
581
+ # --- MODIFIED: Output component as a Textbox with scrollbar ---
582
+ output_dot_product_text = gr.Textbox(
583
+ label="Dot Product Result and Representations",
584
+ lines=20, # This controls the initial height
585
+ autoscroll=True, # Automatically scroll to bottom if new content is added
586
+ interactive=False, # Make it non-editable
587
+ max_lines=None # Allows infinite scrolling (no max height)
588
+ )
589
+
590
+ # Update the gr.Interface call to use the new Textbox output
591
  gr.Interface(
592
  fn=calculate_dot_product_and_representations_independent,
593
  inputs=[
594
+ query_model_radio,
595
+ doc_model_radio,
596
+ query_text_input,
597
+ doc_text_input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  ],
599
+ outputs=output_dot_product_text, # Changed to the Textbox
600
  allow_flagging="never"
601
  )
602