PranavPolavarapu commited on
Commit
b9dbea3
1 Parent(s): d9d19a6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def sample_func(inp):
4
+ pass
5
+ import numpy as np
6
+ import pandas as pd
7
+ import subprocess
8
+ import sys
9
+ subprocess.check_call([sys.executable,'-m','pip','install','tensorflow'])
10
+ subprocess.check_call([sys.executable,'-m','pip','install','scikit-learn'])
11
+ from sklearn.preprocessing import LabelEncoder, LabelBinarizer
12
+ from keras.models import Sequential
13
+ from keras.layers import Dense
14
+ from keras.wrappers.scikit_learn import KerasClassifier
15
+ from sklearn.model_selection import KFold
16
+ from sklearn.ensemble import RandomForestClassifier
17
+
18
+ # Load data
19
+ df = pd.read_csv('ExperimentalMigraneData.csv')
20
+ X = df[['Age','Duration','Frequency','Location','Character','Intensity','Nausea','Vomit','Phonophobia','Photophobia','Visual','Sensory','Dysphasia','Dysarthria','Vertigo','Tinnitus','Hypoacusis','Diplopia','Visual_defect','Ataxia','Conscience','Paresthesia','DPF', 'On Periods']].values #selección de variables de entrada
21
+ Y = df['Types'] #select target
22
+
23
+ # Define the base Keras model
24
+ def baseline_model():
25
+ model = Sequential()
26
+ model.add(Dense(14, input_dim = 24, activation = 'relu')) # Rectified Linear Unit Activation Function
27
+ model.add(Dense(14, activation = 'relu'))
28
+ model.add(Dense(3, activation = 'softmax')) # Softmax for multi-class classification
29
+ model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
30
+ return model
31
+
32
+ # Define the Keras Classifier to use the base model
33
+ estimator = KerasClassifier(build_fn = baseline_model, epochs = 100, batch_size = 10, verbose = 0)
34
+
35
+ # Train the model
36
+ estimator.fit(X, Y)
37
+
38
+ # Define the input component with 24 number inputs
39
+ inputs = []
40
+ for i in range(24):
41
+ inputs.append(gr.inputs.Number(label=df.columns[i]))
42
+
43
+ # Define the output component to show the predicted output
44
+ output = gr.outputs.Label(label="Output")
45
+
46
+ # Define the migraine type mapping dictionary
47
+ migraine_types = {0: 'Menopause Stage',
48
+ 1: 'Menstruation Stage',
49
+ 2: 'Pre-Menopause Stage'}
50
+
51
+ # Define the Gradio interface function
52
+ def predict(*args):
53
+ # Convert the inputs into a numpy array
54
+ input_array = np.array(args).reshape(1, -1)
55
+ # Use the pre-trained estimator to predict the output based on the input array
56
+ y_pred = estimator.predict(input_array)
57
+ # Map the integer prediction to corresponding migraine type
58
+ predicted_type = migraine_types[int(y_pred[0])]
59
+ # Return the predicted output as text
60
+ return predicted_type
61
+
62
+ # Run the Gradio interface
63
+ interface = gr.Interface(fn=predict, inputs=inputs, outputs=output)
64
+
65
+
66
+ Home = gr.Interface(fn=sample_func, inputs=[gr.Image('Beige Classic Circular Fashion Fashion Animated Logo.png', label='ANTICIPATING QOL WITH MENOPAUSAL SEVERITY',shape=[40,40]),
67
+ gr.Textbox('PCL Project - Team: Technohommies', label='FYP', interactive=False).style(container=True),
68
+ gr.Textbox('ANTICIPATING MENSTRUAL MIGRAINE USING DEEP LEARNING', label='Project Title', interactive=False).style(container=True),
69
+ gr.Textbox("Pranav Polavarapu - 19BTRCR008 | Hrishikesh Reddy - 19BTRCR028 | Sai Keerthi Chelluri - 19BTRCR036 | Sai Sharanya Y - 19BTRCR043", label='TEAM', interactive=False).style(container=True),
70
+ gr.Textbox('Dr. S Vijaykumar', label='PCL Project Guide', interactive=False).style(container=True) , outputs=None, title="Final Year Project - TEAM 12", live=True)
71
+
72
+
73
+ Instructions = gr.Interface(fn=sample_func, inputs=[gr.Image('features-Input-Instructions.png', label='Instructions for User Inputs in the Testing Interface',shape=[60,60],interactive=False),
74
+ gr.Textbox("Please Proceed to the Next Tab - 'MENOPAUSAL QOL Model' for accessing the Model's Test Interface, & Provide the necessary inputs according to the instructions mentioned above", label='GO TO NEXT TAB/PAGE', interactive=False).style(container=True)] , outputs=None,
75
+ title="Instructions for User Inputs", live=True)
76
+
77
+
78
+ with gr.Blocks(css=".gradio-container {background-image: url('file=Beige Classic Circular Fashion Fashion Animated Logo.png')}") as demo:
79
+ gr.Markdown( """
80
+ ## Welcome to the
81
+ # MENOPAUSAL QOL PREDICTOR
82
+ #### Please Give your inputs in the page below - as per the specified instructions
83
+ """)
84
+
85
+
86
+ with gr.Box():
87
+ with gr.Column():
88
+ with gr.Tab("MENOPAUSAL QOL PREDICTOR MODEL"):
89
+ with gr.Row(variant='panel'):
90
+ data = gr.TabbedInterface([Home, Instructions, interface], ["Home", "Guidelines", "MENOPAUSAL QOL PREDICTOR MODEL"])
91
+
92
+
93
+
94
+ demo.launch()
95
+