Spaces:
Running on Zero
Running on Zero
File size: 1,355 Bytes
4282c34 b6e173b 4282c34 47332a5 4282c34 47332a5 4282c34 47332a5 4282c34 47332a5 4282c34 47332a5 4282c34 b6e173b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import gradio as gr
import pandas as pd
import skops.io as sio
from huggingface_hub import hf_hub_download
import spaces # Import spaces module
# 1. Download model
model_path = hf_hub_download(
repo_id="iqranaz/Drug-Classification",
filename="drug_pipeline.skops"
)
# 2. Load model
untrusted_types = sio.get_untrusted_types(file=model_path)
pipe = sio.load(model_path, trusted=untrusted_types)
# 3. Add the @spaces.GPU decorator to satisfy ZeroGPU requirement
@spaces.GPU
def predict_drug(age, sex, bp, cholesterol, na_to_k):
df = pd.DataFrame([{
"Age": age,
"Sex": sex,
"BP": bp,
"Cholesterol": cholesterol,
"Na_to_K": na_to_k
}])
pred = pipe.predict(df)[0]
return f"Predicted Drug: {pred}"
# 4. Interface definition
demo = gr.Interface(
fn=predict_drug,
inputs=[
gr.Number(label="Age", value=30),
gr.Dropdown(choices=["M", "F"], label="Sex"),
gr.Dropdown(choices=["HIGH", "NORMAL", "LOW"], label="BP"),
gr.Dropdown(choices=["HIGH", "NORMAL"], label="Cholesterol"),
gr.Number(label="Na_to_K Ratio", value=15.0),
],
outputs="text",
title="Drug Classification Model",
description="Predict drug type based on patient health indicators."
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860) |