Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -123,7 +123,6 @@ for _, row in DF.iterrows():
|
|
123 |
period = row["period"]
|
124 |
group = row["group"]
|
125 |
z = int(row["Z"])
|
126 |
-
# Skip rows with missing period or group
|
127 |
if pd.isna(period) or group is None:
|
128 |
continue
|
129 |
period = int(period)
|
@@ -133,7 +132,7 @@ LAN = [int(z) for z in DF["Z"] if 57 <= int(z) <= 71]
|
|
133 |
ACT = [int(z) for z in DF["Z"] if 89 <= int(z) <= 103]
|
134 |
|
135 |
# -----------------------------
|
136 |
-
# Plotting helpers (Matplotlib)
|
137 |
# -----------------------------
|
138 |
def plot_trend(trend_df: pd.DataFrame, prop_key: str, Z: int, symbol: str):
|
139 |
fig, ax = plt.subplots()
|
@@ -227,39 +226,37 @@ def search_element(query: str):
|
|
227 |
return element_info(query)
|
228 |
|
229 |
# -----------------------------
|
230 |
-
# UI
|
231 |
# -----------------------------
|
232 |
with gr.Blocks(title="Interactive Periodic Table") as demo:
|
233 |
gr.Markdown("# 🧪 Interactive Periodic Table\nClick an element or search by symbol/name/atomic number.")
|
234 |
|
235 |
with gr.Row():
|
236 |
-
#
|
237 |
with gr.Column(scale=1):
|
238 |
gr.Markdown("### Inspector")
|
239 |
search = gr.Textbox(label="Search (symbol/name/Z)", placeholder="e.g., C, Iron, 79")
|
240 |
info = gr.Textbox(label="Properties", lines=10, interactive=False)
|
241 |
facts = gr.Markdown("Select an element to see fun facts.")
|
242 |
-
trend = gr.
|
243 |
|
244 |
search.submit(search_element, inputs=[search], outputs=[info, facts, trend])
|
245 |
|
246 |
gr.Markdown("### Trend heatmap")
|
247 |
prop = gr.Dropdown(choices=[k for k, _ in NUMERIC_PROPS], value="electronegativity", label="Property")
|
248 |
-
heat = gr.
|
249 |
prop.change(lambda k: plot_heatmap(k), inputs=[prop], outputs=[heat])
|
250 |
|
251 |
# Initialize heatmap on load
|
252 |
demo.load(lambda: plot_heatmap("electronegativity"), outputs=[heat])
|
253 |
|
254 |
-
#
|
255 |
with gr.Column(scale=2):
|
256 |
gr.Markdown("### Main Table")
|
257 |
-
# Headers (groups 1-18)
|
258 |
with gr.Row():
|
259 |
for g in range(1, 19):
|
260 |
gr.Markdown(f"**{g}**")
|
261 |
|
262 |
-
# Element grid
|
263 |
for r in range(MAX_PERIOD):
|
264 |
with gr.Row():
|
265 |
for c in range(MAX_GROUP):
|
@@ -288,5 +285,3 @@ with gr.Blocks(title="Interactive Periodic Table") as demo:
|
|
288 |
|
289 |
if __name__ == "__main__":
|
290 |
demo.launch()
|
291 |
-
|
292 |
-
|
|
|
123 |
period = row["period"]
|
124 |
group = row["group"]
|
125 |
z = int(row["Z"])
|
|
|
126 |
if pd.isna(period) or group is None:
|
127 |
continue
|
128 |
period = int(period)
|
|
|
132 |
ACT = [int(z) for z in DF["Z"] if 89 <= int(z) <= 103]
|
133 |
|
134 |
# -----------------------------
|
135 |
+
# Plotting helpers (Matplotlib -> gr.Plot)
|
136 |
# -----------------------------
|
137 |
def plot_trend(trend_df: pd.DataFrame, prop_key: str, Z: int, symbol: str):
|
138 |
fig, ax = plt.subplots()
|
|
|
226 |
return element_info(query)
|
227 |
|
228 |
# -----------------------------
|
229 |
+
# UI (compatible with Gradio 4.29.0)
|
230 |
# -----------------------------
|
231 |
with gr.Blocks(title="Interactive Periodic Table") as demo:
|
232 |
gr.Markdown("# 🧪 Interactive Periodic Table\nClick an element or search by symbol/name/atomic number.")
|
233 |
|
234 |
with gr.Row():
|
235 |
+
# Inspector first so buttons can target these outputs
|
236 |
with gr.Column(scale=1):
|
237 |
gr.Markdown("### Inspector")
|
238 |
search = gr.Textbox(label="Search (symbol/name/Z)", placeholder="e.g., C, Iron, 79")
|
239 |
info = gr.Textbox(label="Properties", lines=10, interactive=False)
|
240 |
facts = gr.Markdown("Select an element to see fun facts.")
|
241 |
+
trend = gr.Plot()
|
242 |
|
243 |
search.submit(search_element, inputs=[search], outputs=[info, facts, trend])
|
244 |
|
245 |
gr.Markdown("### Trend heatmap")
|
246 |
prop = gr.Dropdown(choices=[k for k, _ in NUMERIC_PROPS], value="electronegativity", label="Property")
|
247 |
+
heat = gr.Plot()
|
248 |
prop.change(lambda k: plot_heatmap(k), inputs=[prop], outputs=[heat])
|
249 |
|
250 |
# Initialize heatmap on load
|
251 |
demo.load(lambda: plot_heatmap("electronegativity"), outputs=[heat])
|
252 |
|
253 |
+
# Grid of element buttons
|
254 |
with gr.Column(scale=2):
|
255 |
gr.Markdown("### Main Table")
|
|
|
256 |
with gr.Row():
|
257 |
for g in range(1, 19):
|
258 |
gr.Markdown(f"**{g}**")
|
259 |
|
|
|
260 |
for r in range(MAX_PERIOD):
|
261 |
with gr.Row():
|
262 |
for c in range(MAX_GROUP):
|
|
|
285 |
|
286 |
if __name__ == "__main__":
|
287 |
demo.launch()
|
|
|
|