samarth-kamble's picture
Create app.py
40a914f verified
import gradio as gr
import pickle
# Load model
with open("svm_model.pkl", "rb") as f:
model = pickle.load(f)
# Prediction function
def predict(sex, pregnant, TT4, T3, T4U, FTI, TSH):
try:
# Convert inputs to appropriate types
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)}"
# Gradio UI
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()