|
|
import gradio as gr |
|
|
import pickle |
|
|
|
|
|
|
|
|
with open("svm_model.pkl", "rb") as f: |
|
|
model = pickle.load(f) |
|
|
|
|
|
|
|
|
def predict(sex, pregnant, TT4, T3, T4U, FTI, TSH): |
|
|
try: |
|
|
|
|
|
sex = int(sex) |
|
|
pregnant = int(pregnant) |
|
|
TT4 = float(TT4) |
|
|
T3 = float(T3) |
|
|
T4U = float(T4U) |
|
|
FTI = float(FTI) |
|
|
TSH = float(TSH) |
|
|
prediction = model.predict([[sex, pregnant, TT4, T3, T4U, FTI, TSH]]) |
|
|
label_map = {0: "Hyperthyroid", 1: "Hypothyroid", 2: "Negative"} |
|
|
return f"Prediction: {label_map.get(prediction[0], 'Unknown')}" |
|
|
except Exception as e: |
|
|
return f"Error: {str(e)}" |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=predict, |
|
|
inputs=[ |
|
|
gr.Radio([0, 1], label="Sex (0: Female, 1: Male)"), |
|
|
gr.Radio([0, 1], label="Pregnant (0: No, 1: Yes)"), |
|
|
gr.Number(label="TT4"), |
|
|
gr.Number(label="T3"), |
|
|
gr.Number(label="T4U"), |
|
|
gr.Number(label="FTI"), |
|
|
gr.Number(label="TSH"), |
|
|
], |
|
|
outputs="text", |
|
|
title="Hyperthyroid Prediction", |
|
|
description="Enter patient info to predict thyroid condition using SVM model." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |