Download app.py from zaizou/test_2: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/zaizou/test_2/resolve/main/app.py
- Command line
-
hf download hf://spaces/zaizou/test_2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/zaizou/test_2/resolve/main/app.py
1.26 kB
| import skops.io as sio | |
| import gradio as gr | |
| import pandas as pd | |
| # Get untrusted types from the model file | |
| unknown_types = sio.get_untrusted_types(file="drug_pipeline.skops") | |
| # Load the model while explicitly allowing these types | |
| model = sio.load("drug_pipeline.skops", trusted=unknown_types) | |
| def predict(age, sex, bp, cholesterol, na_to_k): | |
| """ | |
| Predicts the drug type based on user input features. | |
| The preprocessing pipeline inside the model will handle encoding. | |
| """ | |
| # Convert numerical inputs | |
| age = float(age) | |
| na_to_k = float(na_to_k) | |
| # Keep categorical inputs as strings (model will encode them) | |
| features = [age, sex, bp, cholesterol, na_to_k] | |
| # Make prediction (preprocessing is handled inside the pipeline) | |
| prediction = model.predict([features]) | |
| return prediction[0] | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=[ | |
| gr.Textbox(label="Age"), # Numeric | |
| gr.Dropdown(choices=["M", "F"], label="Sex"), # Keep as a string | |
| gr.Dropdown(choices=["LOW", "NORMAL", "HIGH"], label="BP"), # Keep as a string | |
| gr.Dropdown(choices=["NORMAL", "HIGH"], label="Cholesterol"), # Keep as a string | |
| gr.Textbox(label="Na_to_K") # Numeric | |
| ], | |
| outputs="text" | |
| ) | |
| iface.launch() |