Spaces:
Sleeping
Sleeping
Download utils/data.py from nharshavardhana/Periodic-Table-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/nharshavardhana/Periodic-Table-AI/resolve/main/utils/data.py
- Command line
-
hf download hf://spaces/nharshavardhana/Periodic-Table-AI/utils/data.py
-
curl -L -o data.py https://huggingface.co/spaces/nharshavardhana/Periodic-Table-AI/resolve/main/utils/data.py
1.22 kB
| import json | |
| from pathlib import Path | |
| DATA_DIR = Path(__file__).parent.parent / "data" | |
| with open(DATA_DIR / "elements.json", "r", encoding="utf-8") as f: | |
| raw_data = json.load(f)["elements"] | |
| def normalize(element): | |
| return { | |
| "number": element["number"], | |
| "symbol": element["symbol"], | |
| "name": element["name"], | |
| "category": element["category"], | |
| "period": element["period"], | |
| "group": element["group"], | |
| "phase": element["phase"], | |
| "atomic_mass": element["atomic_mass"], | |
| "appearance": element.get("appearance"), | |
| "density": element.get("density"), | |
| "melt": element.get("melt"), | |
| "boil": element.get("boil"), | |
| "electron_configuration": element.get("electron_configuration"), | |
| "shells": element.get("shells"), | |
| "electronegativity": element.get("electronegativity_pauling"), | |
| "discovered_by": element.get("discovered_by"), | |
| "summary": element.get("summary"), | |
| "image": element.get("image", {}).get("url"), | |
| "xpos": element["xpos"], | |
| "ypos": element["ypos"], | |
| } | |
| elements = [normalize(e) for e in raw_data] | |
| element_lookup = { | |
| e["symbol"]: e | |
| for e in elements | |
| } |