samarth-kamble commited on
Commit
f4a9ff1
·
verified ·
1 Parent(s): 60a2b6e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+
4
+ # Load model
5
+ with open("svm_model.pkl", "rb") as f:
6
+ model = pickle.load(f)
7
+
8
+ # Prediction function
9
+ def predict(sex, pregnant, TT4, T3, T4U, FTI, TSH):
10
+ try:
11
+ # Convert inputs to appropriate types
12
+ sex = int(sex)
13
+ pregnant = int(pregnant)
14
+ TT4 = float(TT4)
15
+ T3 = float(T3)
16
+ T4U = float(T4U)
17
+ FTI = float(FTI)
18
+ TSH = float(TSH)
19
+ prediction = model.predict([[sex, pregnant, TT4, T3, T4U, FTI, TSH]])
20
+ label_map = {0: "Hyperthyroid", 1: "Hypothyroid", 2: "Negative"}
21
+ return f"Prediction: {label_map.get(prediction[0], 'Unknown')}"
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
+
25
+ # Gradio UI
26
+ demo = gr.Interface(
27
+ fn=predict,
28
+ inputs=[
29
+ gr.Radio([0, 1], label="Sex (0: Female, 1: Male)"),
30
+ gr.Radio([0, 1], label="Pregnant (0: No, 1: Yes)"),
31
+ gr.Number(label="TT4"),
32
+ gr.Number(label="T3"),
33
+ gr.Number(label="T4U"),
34
+ gr.Number(label="FTI"),
35
+ gr.Number(label="TSH"),
36
+ ],
37
+ outputs="text",
38
+ title="Hyperthyroid Prediction",
39
+ description="Enter patient info to predict thyroid condition using SVM model."
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ demo.launch()