File size: 3,269 Bytes
0f171e0
 
 
 
 
c32f4e8
0f171e0
c32f4e8
0f171e0
be1f278
0f171e0
 
c32f4e8
0f171e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d091f09
b4676e4
d31971a
c32f4e8
 
 
d2017d6
 
 
 
 
8892f9a
3af8149
d091f09
b4676e4
c32f4e8
 
 
 
 
 
 
 
 
68d1b57
c32f4e8
41c8211
 
1c1447a
0f171e0
3a8b80c
e925c8b
5e2b08e
ac5b51b
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
import io


def train_and_predict(data, Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in):
    # Load data from the uploaded CSV
    data = pd.read_csv(io.BytesIO(data))

    # 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)

    # Make prediction
    new_input = [[Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in]]
    predicted_qoil = rf_tuned.predict(new_input)

    return f"The number of barrels produced per day given these inputs is {predicted_qoil[0]}"



iface = gr.Interface(
    fn=train_and_predict,
    inputs=[gr.inputs.File(type="bytes"), "number", "number", "number", "number", "number", "number", "number", "number"],
    outputs="text",
    theme = gr.themes.Monochrome(
    primary_hue="blue",
    secondary_hue="blue",
    neutral_hue="blue",
),
    title="Oil Flow Production & Optimization Application",
    description="""This application is the interface of a machine learning model (utilizing the Random Forest algorithm) that allows Oil and Gas executives with no coding knowledge or experience to enter inputs related to oil production and predict the number of barrels that will be produced per day given those inputs. The executive can engage in scenario planning to optimize oil flow by tweaking/changing various input values to see what would result in greater oil flow. The executive can also ask questions about the model or get explanations of the inputs and/or results via the attached GPT 3.5 chatbot. STEPS: Upload the oil production dataset. Enter the planned or anticipated input values (Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in) and then click Submit. The model will initiate and complete its training and validation in the background using the dataset provided and then return the output value (Qoil) to the user.'
    
    
    Input Features:
    Qwater: Water Flow Rate
    Qgas: Gas Flow Rate
    BHP: Bottom Hole Pressure
    WHP: Wellhead Pressure
    WHT: Wellhead Temperature
    Tsep: Separator Temperature
    Psep: Separator Pressure
    Choke_in: Choke Valve Opening

    Target Variable:
    Qoil: Oil Flow Rate (measured in barrels per day)
    
    Ask questions about the meaning of these values using the application's AI chatbot here: https://aitechproducts.com/oilflowbot.html)

Go back to: <a href="https://aitechproducts.com/oil-gas">Oil & Gas Products</a>""")

iface.launch(auth=(os.environ['USERNAME1'],os.environ['PASSWORD1']))