Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
from joblib import load
|
4 |
-
from tensorflow.keras.models import load_model
|
5 |
-
import tensorflow as tf
|
6 |
-
import requests
|
7 |
-
|
8 |
-
# Load models from Hugging Face (update with your model URLs)
|
9 |
-
def load_huggingface_model(model_url):
|
10 |
-
response = requests.get(model_url)
|
11 |
-
with open("model_temp.joblib" if model_url.endswith(".joblib") else "model_temp.h5", "wb") as f:
|
12 |
-
f.write(response.content)
|
13 |
-
|
14 |
-
return load("model_temp.joblib") if model_url.endswith(".joblib") else load_model("model_temp.h5")
|
15 |
-
|
16 |
-
# URLs of your models on Hugging Face
|
17 |
-
MODEL_URLS = {
|
18 |
-
'Deep Learning': 'https://huggingface.co/your-username/best_DeepLearning_model/resolve/main/best_DeepLearning_model.h5',
|
19 |
-
'Support Vector Regression': 'https://huggingface.co/your-username/best_SVR_model/resolve/main/best_SVR_model.joblib',
|
20 |
-
'Random Forest Regression': 'https://huggingface.co/your-username/best_RandomForestRegressor_model/resolve/main/best_RandomForestRegressor_model.joblib',
|
21 |
-
'Decision Tree Regression': 'https://huggingface.co/your-username/best_DecisionTreeRegressor_model/resolve/main/best_DecisionTreeRegressor_model.joblib'
|
22 |
-
}
|
23 |
-
|
24 |
-
# Prediction function
|
25 |
-
def multi_inputs(input1, input2, input3, input4, input5, input6, input7, input8, input9, input10, input11, input12):
|
26 |
-
try:
|
27 |
-
model = load_huggingface_model(MODEL_URLS[input12])
|
28 |
-
|
29 |
-
# Convert numeric inputs to float
|
30 |
-
input4, input5, input9 = float(input4), float(input5), float(input9)
|
31 |
-
|
32 |
-
# Create input list with proper types
|
33 |
-
inputs_to_transform = [
|
34 |
-
str(input1), str(input2), str(input3), input4, input5,
|
35 |
-
float(input6), float(input7), float(input8), input9,
|
36 |
-
str(input10), str(input11)
|
37 |
-
]
|
38 |
-
|
39 |
-
# Reshape input for prediction
|
40 |
-
input_data = np.array([inputs_to_transform], dtype=np.float32)
|
41 |
-
|
42 |
-
if input12 == 'Deep Learning':
|
43 |
-
tensor_input = tf.convert_to_tensor(input_data)
|
44 |
-
prediction = model.predict(tensor_input, verbose=0)
|
45 |
-
return float(prediction[0][0])
|
46 |
-
else:
|
47 |
-
prediction = model.predict(input_data)
|
48 |
-
return float(prediction[0])
|
49 |
-
|
50 |
-
except Exception as e:
|
51 |
-
return f"Error in prediction: {str(e)}"
|
52 |
-
|
53 |
-
# Gradio Interface
|
54 |
-
interface = gr.Interface(
|
55 |
-
fn=multi_inputs,
|
56 |
-
inputs=[
|
57 |
-
gr.Radio(['male', 'female'], label='Gender'),
|
58 |
-
gr.Dropdown(['Race1', 'Race2'], label='Race'),
|
59 |
-
gr.Dropdown([20, 30, 40], label='Age'),
|
60 |
-
gr.Number(label='Height (cm)'),
|
61 |
-
gr.Number(label='Weight (kg)'),
|
62 |
-
gr.Radio([0.0, 1.0], label='Diabetes'),
|
63 |
-
gr.Radio([0.0, 1.0], label='Simvastatin'),
|
64 |
-
gr.Radio([0.0, 1.0], label='Amiodarone'),
|
65 |
-
gr.Number(label='INR'),
|
66 |
-
gr.Dropdown(['Cyp2C9_A', 'Cyp2C9_B'], label='Cyp2C9 genotypes'),
|
67 |
-
gr.Dropdown(['VKORC1_A', 'VKORC1_B'], label='VKORC1 genotypes'),
|
68 |
-
gr.Dropdown(['Deep Learning', 'Support Vector Regression', 'Random Forest Regression', 'Decision Tree Regression'], label='Model Selection')
|
69 |
-
],
|
70 |
-
outputs="number",
|
71 |
-
live=False
|
72 |
-
)
|
73 |
-
|
74 |
-
if __name__ == '__main__':
|
75 |
-
interface.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|