naughtondale commited on
Commit
01e93c6
1 Parent(s): 8bd9b51

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.ensemble import RandomForestRegressor
6
+ from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
7
+ import gradio as gr
8
+
9
+ # Read the dataset
10
+ data = pd.read_csv('Well_Rates.csv')
11
+
12
+ # Define input features and target variable
13
+ input_features = ['Qwater', 'Qgas', 'BHP', 'WHP', 'WHT', 'Tsep', 'Psep', 'Choke_in']
14
+ target_variable = 'Qoil'
15
+
16
+ # Split the dataset into training and testing sets
17
+ X = data[input_features]
18
+ y = data[target_variable]
19
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
20
+
21
+ # Train the random forest regression model
22
+ rf = RandomForestRegressor(n_estimators=100, random_state=42)
23
+ rf.fit(X_train, y_train)
24
+
25
+ # Fine-tune the model
26
+ rf_tuned = RandomForestRegressor(n_estimators=200, max_depth=10, random_state=42)
27
+ rf_tuned.fit(X_train, y_train)
28
+
29
+ def predict_qoil(Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in):
30
+ new_input = [[Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in]]
31
+ predicted_qoil = rf_tuned.predict(new_input)
32
+ return predicted_qoil[0]
33
+
34
+ iface = gr.Interface(
35
+ fn=predict_qoil,
36
+ inputs=["number", "number", "number", "number", "number", "number", "number", "number"],
37
+ outputs="number",
38
+ interpretation="default")
39
+ iface.launch()