ThankGod commited on
Commit
21c3f02
·
1 Parent(s): 6faa6c4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import warnings
2
+ warnings.filterwarnings("ignore")
3
+ import pickle
4
+ import pandas as pd
5
+ import numpy as np
6
+ import gradio as gr
7
+ import random
8
+
9
+ def import_model():
10
+ model_names = ['random_forest', 'xgboost', 'decision_tree']
11
+ loaded_models = tuple()
12
+ for model_name in model_names:
13
+ with open(f'models/{model_name}.pkl', 'rb') as file:
14
+ model = pickle.load(file)
15
+ loaded_models += (model,)
16
+ return loaded_models
17
+
18
+ def predict_liquid_rate(*input):
19
+ input_list = list(input)
20
+ inp_arr = np.array(input_list[:-1]).reshape(1, -1)
21
+ random_forest_model, xgboost_model, decision_tree_model = import_model()
22
+ model_selection = input_list[-1]
23
+ print(model_selection)
24
+
25
+ result = {}
26
+ model_names = {
27
+ 'XGBoost': 'XGBoost Oil Rate',
28
+ 'Random Forest': 'Random Forest Oil Rate',
29
+ 'Decision Tree': 'Decision Tree Oil Rate',
30
+ 'Prophet Model': 'Prophet Model Oil Rate'
31
+ }
32
+ xg_output = ''
33
+ dt_output = ''
34
+ rf_output = ''
35
+ for choice in model_selection:
36
+ if choice == 'XGBoost':
37
+ xg_pred = xgboost_model.predict(inp_arr)
38
+ result[choice] = xg_pred[0]
39
+ xg_output = f"{model_names['XGBoost']}: {result['XGBoost']:.2f} Bbls/day"
40
+ elif choice == 'Decision Tree':
41
+ dt_pred = decision_tree_model.predict(inp_arr)
42
+ result[choice] = dt_pred[0]
43
+ dt_output = f"{model_names['Decision Tree']}: {result['Decision Tree']:.2f} Bbls/day"
44
+ elif choice == 'Random Forest':
45
+ rf_pred = random_forest_model.predict(inp_arr)
46
+ result[choice] = rf_pred[0]
47
+ rf_output = f"{model_names['Random Forest']}: {result['Random Forest']:.2f} Bbls/day"
48
+
49
+ return xg_output, dt_output, rf_output
50
+
51
+ with gr.Blocks() as demo:
52
+ gr.Markdown(
53
+ """
54
+ # Oil Rate Prediction
55
+ Use this table as Reference for Last Well test data.
56
+ """)
57
+ with gr.Column():
58
+ with gr.Box():
59
+ frame_output = gr.Dataframe(
60
+ value=[['2022-12-23', 32, 1000, 280, 0.45, 775.12]],
61
+ headers=['Date', 'Choke', 'FTHP', 'FLP', 'BS&W', 'OilRate'],
62
+ datatype=["str", "number", "number", "number", "number", "number"],
63
+ )
64
+
65
+ gr.Markdown(
66
+ """ Use the different input slider to select new welltest information
67
+ """)
68
+ with gr.Box():
69
+ choke = gr.Slider(minimum=0, maximum=100, value=32, step=2, label="Choke Size (1/64\")", interactive=True)
70
+ fthp = gr.Slider(minimum=500, maximum=5000, step=1, value=1000, label="Tubing Head Pressure (FTHP)(psi)", interactive=True)
71
+ flp = gr.Slider(minimum=0, maximum=5000, step=1, value=280,label="Flow Line Pressure (FLP)(psi)", interactive=True)
72
+ bsw = gr.Slider(minimum=0, maximum=100, value=0.45, label="Basic Sediment and Water (BS&W)(%)", interactive=True)
73
+
74
+ gr.Markdown(
75
+ """ Use the different trained models to perform Oil rate prediction
76
+ """)
77
+ # Output Controls
78
+ with gr.Column():
79
+ select_model = gr.CheckboxGroup(choices=["Random Forest", "XGBoost", "Decision Tree"], value='XGBoost', label="Select Model", info="Select Model to make prediction", interactive=True)
80
+ btn_predict = gr.Button("Test Prediction")
81
+ xg_output = gr.Label(label="XGBoost model")
82
+ dt_output = gr.Label(label="Decision Tree")
83
+ rf_output = gr.Label(label="Random Forest")
84
+
85
+
86
+ input_items = [choke, fthp, flp, bsw, select_model]
87
+ btn_predict.click(fn=predict_liquid_rate, inputs=input_items, outputs=[xg_output,dt_output,rf_output])
88
+ #gr.describe()
89
+
90
+ demo.launch(debug=True, share=True)