gkdivya commited on
Commit
596d7d1
·
verified ·
1 Parent(s): f70954b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -85,6 +85,24 @@ def render_results_md(df, show_score=True):
85
 
86
  return md
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  def on_state_change(state):
90
  if not state:
@@ -115,8 +133,12 @@ def on_district_change(state, district):
115
  # Wrapped search functions
116
  # ----------------------------------------------------
117
  def rapid_search_and_render(name, state, district, block):
118
- candidates, _ = search_candidates(name, state, district, block)
119
- return render_results_md(candidates, show_score=True)
 
 
 
 
120
 
121
 
122
  def web_search_and_render(name, state, district, block):
@@ -169,6 +191,10 @@ with gr.Blocks(title="State School Fuzzy Matcher") as demo:
169
  gr.Markdown("### 🔎 Rapid Search Results")
170
  rapid_results_md = gr.Markdown()
171
 
 
 
 
 
172
  # ================= WEB SEARCH =================
173
  gr.Markdown("### 🌐 Web Search (Locked)")
174
  gr.Markdown(
@@ -203,7 +229,7 @@ with gr.Blocks(title="State School Fuzzy Matcher") as demo:
203
  search_btn.click(
204
  fn=rapid_search_and_render,
205
  inputs=[school_input, state_dd, district_dd, block_dd],
206
- outputs=rapid_results_md,
207
  )
208
 
209
  unlock_btn.click(
 
85
 
86
  return md
87
 
88
+ def render_best_md(df):
89
+ if df is None or df.empty:
90
+ return "_No confident best match found._"
91
+
92
+ r = df.iloc[0]
93
+
94
+ return f"""
95
+ ### ⭐ Best Match
96
+
97
+ - **School Name:** {r.get("School_Name", "")}
98
+ - **UDISE Code:** {r.get("UDISE_Code", "")}
99
+ - **State:** {r.get("State", "")}
100
+ - **District:** {r.get("District", "")}
101
+ - **Block:** {r.get("Block", "")}
102
+ - **Score:** {float(r.get("Score", 0)):.2f}
103
+ """
104
+
105
+
106
 
107
  def on_state_change(state):
108
  if not state:
 
133
  # Wrapped search functions
134
  # ----------------------------------------------------
135
  def rapid_search_and_render(name, state, district, block):
136
+ candidates, best = search_candidates(name, state, district, block)
137
+
138
+ table_md = render_results_md(candidates, show_score=True)
139
+ best_md = render_best_md(best)
140
+
141
+ return table_md, best_md
142
 
143
 
144
  def web_search_and_render(name, state, district, block):
 
191
  gr.Markdown("### 🔎 Rapid Search Results")
192
  rapid_results_md = gr.Markdown()
193
 
194
+ gr.Markdown("### ⭐ Best Rapid Match")
195
+ best_result_md = gr.Markdown()
196
+
197
+
198
  # ================= WEB SEARCH =================
199
  gr.Markdown("### 🌐 Web Search (Locked)")
200
  gr.Markdown(
 
229
  search_btn.click(
230
  fn=rapid_search_and_render,
231
  inputs=[school_input, state_dd, district_dd, block_dd],
232
+ outputs=[rapid_results_md, best_result_md],
233
  )
234
 
235
  unlock_btn.click(