File size: 1,347 Bytes
01e93c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
import gradio as gr

# Read the dataset
data = pd.read_csv('Well_Rates.csv')

# Define input features and target variable
input_features = ['Qwater', 'Qgas', 'BHP', 'WHP', 'WHT', 'Tsep', 'Psep', 'Choke_in']
target_variable = 'Qoil'

# Split the dataset into training and testing sets
X = data[input_features]
y = data[target_variable]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train the random forest regression model
rf = RandomForestRegressor(n_estimators=100, random_state=42)
rf.fit(X_train, y_train)

# Fine-tune the model
rf_tuned = RandomForestRegressor(n_estimators=200, max_depth=10, random_state=42)
rf_tuned.fit(X_train, y_train)

def predict_qoil(Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in):
    new_input = [[Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in]]
    predicted_qoil = rf_tuned.predict(new_input)
    return predicted_qoil[0]

iface = gr.Interface(
    fn=predict_qoil, 
    inputs=["number", "number", "number", "number", "number", "number", "number", "number"], 
    outputs="number",
    interpretation="default")
iface.launch()