Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,38 +53,36 @@ def render_header(show_score=True):
|
|
| 53 |
gr.Markdown("**Score**")
|
| 54 |
|
| 55 |
|
| 56 |
-
def
|
| 57 |
-
comps = []
|
| 58 |
-
|
| 59 |
if df is None or df.empty:
|
| 60 |
-
|
| 61 |
-
return comps
|
| 62 |
|
| 63 |
# Header
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if show_score:
|
| 71 |
-
gr.Markdown("**Score**")
|
| 72 |
|
| 73 |
-
# Rows
|
| 74 |
for _, r in df.iterrows():
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
return comps
|
| 88 |
|
| 89 |
|
| 90 |
|
|
@@ -93,11 +91,13 @@ def render_results(df, show_score=True):
|
|
| 93 |
# ----------------------------------------------------
|
| 94 |
def rapid_search_and_render(name, state, district, block):
|
| 95 |
candidates, _ = search_candidates(name, state, district, block)
|
| 96 |
-
return
|
|
|
|
| 97 |
|
| 98 |
def web_search_and_render(name, state, district, block):
|
| 99 |
results = on_search_web(name, state, district, block)
|
| 100 |
-
return
|
|
|
|
| 101 |
|
| 102 |
# ----------------------------------------------------
|
| 103 |
# Unlock Web Search
|
|
@@ -142,7 +142,7 @@ with gr.Blocks(title="State School Fuzzy Matcher") as demo:
|
|
| 142 |
|
| 143 |
# ================= RAPID RESULTS =================
|
| 144 |
gr.Markdown("### π Rapid Search Results")
|
| 145 |
-
|
| 146 |
|
| 147 |
# ================= WEB SEARCH =================
|
| 148 |
gr.Markdown("### π Web Search (Locked)")
|
|
@@ -159,7 +159,7 @@ with gr.Blocks(title="State School Fuzzy Matcher") as demo:
|
|
| 159 |
web_status = gr.Markdown("")
|
| 160 |
|
| 161 |
search_web_btn = gr.Button("Search Web", interactive=False)
|
| 162 |
-
|
| 163 |
|
| 164 |
# ================= Wiring =================
|
| 165 |
state_dd.change(
|
|
@@ -175,9 +175,9 @@ with gr.Blocks(title="State School Fuzzy Matcher") as demo:
|
|
| 175 |
)
|
| 176 |
|
| 177 |
search_btn.click(
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
)
|
| 182 |
|
| 183 |
unlock_btn.click(
|
|
@@ -187,9 +187,9 @@ with gr.Blocks(title="State School Fuzzy Matcher") as demo:
|
|
| 187 |
)
|
| 188 |
|
| 189 |
search_web_btn.click(
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
)
|
| 194 |
|
| 195 |
if __name__ == "__main__":
|
|
|
|
| 53 |
gr.Markdown("**Score**")
|
| 54 |
|
| 55 |
|
| 56 |
+
def render_results_md(df, show_score=True):
|
|
|
|
|
|
|
| 57 |
if df is None or df.empty:
|
| 58 |
+
return "β No results found."
|
|
|
|
| 59 |
|
| 60 |
# Header
|
| 61 |
+
headers = ["School Name", "UDISE Code", "State", "District", "Block"]
|
| 62 |
+
if show_score:
|
| 63 |
+
headers.append("Score")
|
| 64 |
+
|
| 65 |
+
md = "| " + " | ".join(headers) + " |\n"
|
| 66 |
+
md += "| " + " | ".join(["---"] * len(headers)) + " |\n"
|
|
|
|
|
|
|
| 67 |
|
|
|
|
| 68 |
for _, r in df.iterrows():
|
| 69 |
+
row = [
|
| 70 |
+
str(r.get("School_Name", "")),
|
| 71 |
+
str(r.get("UDISE_Code", "")),
|
| 72 |
+
str(r.get("State", "")),
|
| 73 |
+
str(r.get("District", "")),
|
| 74 |
+
str(r.get("Block", "")),
|
| 75 |
+
]
|
| 76 |
+
if show_score:
|
| 77 |
+
score = r.get("Score", "")
|
| 78 |
+
row.append("" if pd.isna(score) else f"{float(score):.2f}")
|
| 79 |
+
|
| 80 |
+
md += "| " + " | ".join(row) + " |\n"
|
| 81 |
+
|
| 82 |
+
return md
|
| 83 |
+
|
| 84 |
+
|
| 85 |
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
|
|
|
|
| 91 |
# ----------------------------------------------------
|
| 92 |
def rapid_search_and_render(name, state, district, block):
|
| 93 |
candidates, _ = search_candidates(name, state, district, block)
|
| 94 |
+
return render_results_md(candidates, show_score=True)
|
| 95 |
+
|
| 96 |
|
| 97 |
def web_search_and_render(name, state, district, block):
|
| 98 |
results = on_search_web(name, state, district, block)
|
| 99 |
+
return render_results_md(results, show_score=False)
|
| 100 |
+
|
| 101 |
|
| 102 |
# ----------------------------------------------------
|
| 103 |
# Unlock Web Search
|
|
|
|
| 142 |
|
| 143 |
# ================= RAPID RESULTS =================
|
| 144 |
gr.Markdown("### π Rapid Search Results")
|
| 145 |
+
rapid_results_md = gr.Markdown()
|
| 146 |
|
| 147 |
# ================= WEB SEARCH =================
|
| 148 |
gr.Markdown("### π Web Search (Locked)")
|
|
|
|
| 159 |
web_status = gr.Markdown("")
|
| 160 |
|
| 161 |
search_web_btn = gr.Button("Search Web", interactive=False)
|
| 162 |
+
web_results_md = gr.Markdown()
|
| 163 |
|
| 164 |
# ================= Wiring =================
|
| 165 |
state_dd.change(
|
|
|
|
| 175 |
)
|
| 176 |
|
| 177 |
search_btn.click(
|
| 178 |
+
fn=rapid_search_and_render,
|
| 179 |
+
inputs=[school_input, state_dd, district_dd, block_dd],
|
| 180 |
+
outputs=rapid_results_md,
|
| 181 |
)
|
| 182 |
|
| 183 |
unlock_btn.click(
|
|
|
|
| 187 |
)
|
| 188 |
|
| 189 |
search_web_btn.click(
|
| 190 |
+
fn=web_search_and_render,
|
| 191 |
+
inputs=[school_input, state_dd, district_dd, block_dd],
|
| 192 |
+
outputs=web_results_md,
|
| 193 |
)
|
| 194 |
|
| 195 |
if __name__ == "__main__":
|