Spaces:
Sleeping

test_2 / app.py
zaizou's picture
app.py
d6e847b verified
Raw History Blame Contribute Delete
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()