Spaces:
Runtime error
Runtime error
import gradio as gr | |
def sample_func(inp): | |
pass | |
import numpy as np | |
import pandas as pd | |
import subprocess | |
import sys | |
subprocess.check_call([sys.executable,'-m','pip','install','tensorflow']) | |
subprocess.check_call([sys.executable,'-m','pip','install','scikit-learn']) | |
from sklearn.preprocessing import LabelEncoder, LabelBinarizer | |
from keras.models import Sequential | |
from keras.layers import Dense | |
from keras.wrappers.scikit_learn import KerasClassifier | |
from sklearn.model_selection import KFold | |
from sklearn.ensemble import RandomForestClassifier | |
# Load data | |
df = pd.read_csv('ExperimentalMigraneData.csv') | |
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 | |
Y = df['Types'] #select target | |
# Define the base Keras model | |
def baseline_model(): | |
model = Sequential() | |
model.add(Dense(14, input_dim = 24, activation = 'relu')) # Rectified Linear Unit Activation Function | |
model.add(Dense(14, activation = 'relu')) | |
model.add(Dense(3, activation = 'softmax')) # Softmax for multi-class classification | |
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy']) | |
return model | |
# Define the Keras Classifier to use the base model | |
estimator = KerasClassifier(build_fn = baseline_model, epochs = 100, batch_size = 10, verbose = 0) | |
# Train the model | |
estimator.fit(X, Y) | |
# Define the input component with 24 number inputs | |
inputs = [] | |
for i in range(24): | |
inputs.append(gr.inputs.Number(label=df.columns[i])) | |
# Define the output component to show the predicted output | |
output = gr.outputs.Label(label="Output") | |
# Define the migraine type mapping dictionary | |
migraine_types = {0: 'Menopause Stage', | |
1: 'Menstruation Stage', | |
2: 'Pre-Menopause Stage'} | |
# Define the Gradio interface function | |
def predict(*args): | |
# Convert the inputs into a numpy array | |
input_array = np.array(args).reshape(1, -1) | |
# Use the pre-trained estimator to predict the output based on the input array | |
y_pred = estimator.predict(input_array) | |
# Map the integer prediction to corresponding migraine type | |
predicted_type = migraine_types[int(y_pred[0])] | |
# Return the predicted output as text | |
return predicted_type | |
# Run the Gradio interface | |
interface = gr.Interface(fn=predict, inputs=inputs, outputs=output) | |
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]), | |
gr.Textbox('PCL Project - Team: Technohommies', label='FYP', interactive=False).style(container=True), | |
gr.Textbox('ANTICIPATING MENSTRUAL MIGRAINE USING DEEP LEARNING', label='Project Title', interactive=False).style(container=True), | |
gr.Textbox("Pranav Polavarapu - 19BTRCR008 | Hrishikesh Reddy - 19BTRCR028 | Sai Keerthi Chelluri - 19BTRCR036 | Sai Sharanya Y - 19BTRCR043", label='TEAM', interactive=False).style(container=True), | |
gr.Textbox('Dr. S Vijaykumar', label='PCL Project Guide', interactive=False).style(container=True)], outputs=None, title="Project Centric Learnning", live=True) | |
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), | |
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, | |
title="Instructions for User Inputs", live=True) | |
with gr.Blocks(css=".gradio-container {background-image: url('file=Beige Classic Circular Fashion Fashion Animated Logo.png')}") as demo: | |
gr.Markdown( """ | |
## Welcome to the | |
# MENOPAUSAL QOL PREDICTOR | |
#### Please Give your inputs in the page below - as per the specified instructions | |
""") | |
with gr.Box(): | |
with gr.Column(): | |
with gr.Tab("MENOPAUSAL QOL PREDICTOR MODEL"): | |
with gr.Row(variant='panel'): | |
data = gr.TabbedInterface([Home, Instructions, interface], ["Home", "Guidelines", "MENOPAUSAL QOL PREDICTOR MODEL"]) | |
demo.launch() | |