naveenus commited on
Commit
8f108e4
Β·
verified Β·
1 Parent(s): a36206a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -38,13 +38,18 @@ for fn, hdr in [
38
  # Inference functions
39
  # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
40
  def run_stage1(question, model_name):
41
- """Return top3 coarse subjects + duration."""
42
  start = time.time()
43
  clf = pipeline("zero-shot-classification", model=model_name)
44
  out = clf(question, candidate_labels=coarse_labels)
45
  labels, scores = out["labels"][:3], out["scores"][:3]
46
- duration = round(time.time()-start,3)
47
- return labels, duration
 
 
 
 
 
 
48
 
49
  def run_stage2(question, model_name, subject):
50
  """Return top3 fine topics + duration."""
@@ -84,20 +89,17 @@ with gr.Blocks() as demo:
84
 
85
  with gr.Row():
86
  question_input = gr.Textbox(lines=3, label="Enter your question")
87
- model_input = gr.Dropdown(
88
- choices=MODEL_CHOICES, value=MODEL_CHOICES[0], label="Choose model"
89
- )
90
  go_button = gr.Button("Run Stage 1")
91
 
92
- # Stage 1 outputs
93
- subj_radio = gr.Radio(choices=[], label="Top-3 Subjects",
94
- info="Select to re-run Stage 2 for a different subject")
95
  stage1_time = gr.Textbox(label="Stage 1 Time")
96
 
97
  go_button.click(
98
- fn=lambda q,m: (*run_stage1(q,m),),
99
  inputs=[question_input, model_input],
100
- outputs=[subj_radio, stage1_time]
101
  )
102
 
103
  # Stage 2 UI
 
38
  # Inference functions
39
  # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
40
  def run_stage1(question, model_name):
 
41
  start = time.time()
42
  clf = pipeline("zero-shot-classification", model=model_name)
43
  out = clf(question, candidate_labels=coarse_labels)
44
  labels, scores = out["labels"][:3], out["scores"][:3]
45
+ duration = round(time.time() - start, 3)
46
+
47
+ # Build the label mapping
48
+ label_dict = {lbl: round(score,3) for lbl,score in zip(labels, scores)}
49
+ # Prepare Radio update
50
+ radio_update = gr.update(choices=labels, value=labels[0])
51
+
52
+ return label_dict, radio_update, f"⏱ {duration}s"
53
 
54
  def run_stage2(question, model_name, subject):
55
  """Return top3 fine topics + duration."""
 
89
 
90
  with gr.Row():
91
  question_input = gr.Textbox(lines=3, label="Enter your question")
92
+ model_input = gr.Dropdown(choices=MODEL_CHOICES, value=MODEL_CHOICES[0], label="Choose model")
 
 
93
  go_button = gr.Button("Run Stage 1")
94
 
95
+ subject_out = gr.Label(num_top_classes=3, label="Top-3 Subjects")
96
+ subj_radio = gr.Radio(choices=[], label="Select Subject for Stage 2")
 
97
  stage1_time = gr.Textbox(label="Stage 1 Time")
98
 
99
  go_button.click(
100
+ fn=run_stage1,
101
  inputs=[question_input, model_input],
102
+ outputs=[subject_out, subj_radio, stage1_time]
103
  )
104
 
105
  # Stage 2 UI