File size: 1,243 Bytes
40a914f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()