naughtondale commited on
Commit
d31971a
1 Parent(s): 0f171e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -56
app.py CHANGED
@@ -5,9 +5,6 @@ from sklearn.model_selection import train_test_split
5
  from sklearn.ensemble import RandomForestRegressor
6
  import gradio as gr
7
  import openai
8
- from gradio import inputs as gr_inputs
9
- from gradio import outputs as gr_outputs
10
- from gradio import components as gr_components
11
 
12
  # Set up OpenAI API credentials
13
  openai.api_key = "YOUR_OPENAI_API_KEY"
@@ -54,66 +51,35 @@ def ask_openai(question):
54
  answer = response.choices[0].text.strip()
55
  return answer
56
 
57
- iface = gr.Interface(
58
- fn=train_and_predict,
59
- inputs=[
60
- gr_inputs.Dataframe(label="Upload CSV"),
61
- gr_inputs.Number(label="Qwater"),
62
- gr_inputs.Number(label="Qgas"),
63
- gr_inputs.Number(label="BHP"),
64
- gr_inputs.Number(label="WHP"),
65
- gr_inputs.Number(label="WHT"),
66
- gr_inputs.Number(label="Tsep"),
67
- gr_inputs.Number(label="Psep"),
68
- gr_inputs.Number(label="Choke_in"),
69
- ],
70
- outputs=gr_outputs.Textbox(label="Prediction"),
71
- title="Oil Production Prediction",
72
- description="""This application is the interface of a machine learning model 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. Upload the oil production dataset. Enter the input values (Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in) and then click Submit. The model will initiate and complete its training in the background using the dataset provided and then return the output value (Qoil) to you.
73
-
74
- Input Features:
75
- Qwater: Water Flow Rate
76
- Qgas: Gas Flow Rate
77
- BHP: Bottom Hole Pressure
78
- WHP: Wellhead Pressure
79
- WHT: Wellhead Temperature
80
- Tsep: Separator Temperature
81
- Psep: Separator Pressure
82
- Choke_in: Choke Valve Opening
83
-
84
- Target Variable:
85
- Qoil: Oil Flow Rate (measured in barrels per day)"""
86
- )
87
-
88
- # Chatbot components
89
- question_input = gr_inputs.Textbox(label="Ask a Question")
90
- chat_output = gr_outputs.Textbox(label="Chatbot Response")
91
- submit_button = gr_components.Button(label="Submit")
92
- reset_button = gr_components.Button(label="Reset")
93
-
94
- # Function to handle chatbot submission
95
  def handle_submit(data, Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in, question):
96
  prediction = train_and_predict(data, Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in)
97
  answer = ask_openai(question)
98
  return prediction, answer
99
 
100
- # Function to handle reset button
101
  def handle_reset():
102
  iface.clear_input()
103
 
104
- # Interface layout
105
- interface_layout = [
106
- [iface.inputs[0]],
107
- [iface.inputs[1], iface.inputs[2], iface.inputs[3], iface.inputs[4], iface.inputs[5], iface.inputs[6], iface.inputs[7], iface.inputs[8]],
108
- [submit_button, reset_button],
109
- [iface.outputs[0]],
110
- [question_input],
111
- [chat_output]
112
- ]
113
-
114
- # Interface callback functions
115
- iface.input_callback = handle_submit
116
- iface.reset_callback = handle_reset
 
 
 
 
 
 
 
 
 
117
 
118
- iface.interface_layout = interface_layout
119
  iface.launch()
 
5
  from sklearn.ensemble import RandomForestRegressor
6
  import gradio as gr
7
  import openai
 
 
 
8
 
9
  # Set up OpenAI API credentials
10
  openai.api_key = "YOUR_OPENAI_API_KEY"
 
51
  answer = response.choices[0].text.strip()
52
  return answer
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  def handle_submit(data, Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in, question):
55
  prediction = train_and_predict(data, Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in)
56
  answer = ask_openai(question)
57
  return prediction, answer
58
 
 
59
  def handle_reset():
60
  iface.clear_input()
61
 
62
+ iface = gr.Interface(
63
+ fn=handle_submit,
64
+ inputs=[
65
+ gr.inputs.File(label="Upload CSV"),
66
+ gr.inputs.Number(label="Qwater"),
67
+ gr.inputs.Number(label="Qgas"),
68
+ gr.inputs.Number(label="BHP"),
69
+ gr.inputs.Number(label="WHP"),
70
+ gr.inputs.Number(label="WHT"),
71
+ gr.inputs.Number(label="Tsep"),
72
+ gr.inputs.Number(label="Psep"),
73
+ gr.inputs.Number(label="Choke_in"),
74
+ gr.inputs.Textbox(label="Ask a Question")
75
+ ],
76
+ outputs=[
77
+ gr.outputs.Textbox(label="Prediction"),
78
+ gr.outputs.Textbox(label="Chatbot Response")
79
+ ],
80
+ title="Oil Production Prediction",
81
+ description="""This application is the interface of a machine learning model 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. Upload the oil production dataset and enter the input values (Qwater, Qgas, BHP, WHP, WHT, Tsep, Psep, Choke_in). You can also ask questions about the dataset or the meaning of inputs. The model will initiate and complete its training in the background using the dataset provided and then return the output value (Qoil) along with an answer from the chatbot to you.
82
+ """
83
+ )
84
 
 
85
  iface.launch()