Download app.py from NH-640/Indice: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/NH-640/Indice/resolve/main/app.py
- Command line
-
hf download hf://spaces/NH-640/Indice/app.py
-
curl -L -o app.py https://huggingface.co/spaces/NH-640/Indice/resolve/main/app.py
2.26 kB
| import streamlit as st | |
| st.set_page_config(page_title="Miller Indices Calculator", layout="centered") | |
| st.title("π· Miller Indices Calculator") | |
| st.write("Compute Miller indices (h, k, l) from intercepts along crystal axes.") | |
| st.markdown("---") | |
| st.header("π₯ Input Intercepts") | |
| st.write("Enter intercepts along x, y, z axes (use β for parallel planes)") | |
| x = st.text_input("Intercept along X-axis (a)", "1") | |
| y = st.text_input("Intercept along Y-axis (b)", "1") | |
| z = st.text_input("Intercept along Z-axis (c)", "1") | |
| def parse_input(val): | |
| if val.lower() in ["inf", "β"]: | |
| return float("inf") | |
| return float(val) | |
| def calculate_miller(x, y, z): | |
| try: | |
| x, y, z = parse_input(x), parse_input(y), parse_input(z) | |
| # Step 1: Take reciprocals | |
| h = 0 if x == float("inf") else 1/x | |
| k = 0 if y == float("inf") else 1/y | |
| l = 0 if z == float("inf") else 1/z | |
| reciprocals = [h, k, l] | |
| # Step 2: Find LCM multiplier | |
| denominators = [] | |
| for val in reciprocals: | |
| if val != 0: | |
| frac = str(val).split(".") | |
| if len(frac) > 1: | |
| denominators.append(10**len(frac[1])) | |
| multiplier = max(denominators) if denominators else 1 | |
| hkl = [int(round(val * multiplier)) for val in reciprocals] | |
| return reciprocals, hkl | |
| except: | |
| return None, None | |
| if st.button("Calculate"): | |
| reciprocals, hkl = calculate_miller(x, y, z) | |
| if hkl: | |
| st.success(f"β Miller Indices: ({hkl[0]} {hkl[1]} {hkl[2]})") | |
| st.subheader("π Step-by-Step") | |
| st.write(f"Reciprocals β {reciprocals}") | |
| st.write(f"Scaled to integers β {hkl}") | |
| st.markdown("---") | |
| st.subheader("π Concept Diagram") | |
| st.code(""" | |
| 3D Axis Representation: | |
| Z | |
| | | |
| | | |
| |____ Y | |
| / | |
| / | |
| X | |
| Intercepts example: | |
| X = 1, Y = 2, Z = β | |
| Step 1: Reciprocals | |
| (1, 1/2, 0) | |
| Step 2: Multiply to clear fractions | |
| (2, 1, 0) | |
| Final Miller Index: | |
| (2 1 0) | |
| """) | |
| else: | |
| st.error("Invalid input. Please enter valid numbers or β.") |