PebinAPJ commited on
Commit
d742e8f
·
verified ·
1 Parent(s): d5a484a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.linear_model import LinearRegression
5
+ from sklearn.model_selection import train_test_split
6
+ import matplotlib.pyplot as plt
7
+
8
+ # Load the dataset and preprocess
9
+ df = pd.read_csv('GOOG.csv')
10
+ df = df.drop(columns=[
11
+ 'symbol', 'adjClose', 'adjHigh', 'adjLow', 'adjOpen', 'adjVolume', 'divCash', 'splitFactor'
12
+ ], axis=1)
13
+
14
+ # Split the data
15
+ X = df[['open', 'high', 'low', 'volume']].values
16
+ y = df['close'].values
17
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
18
+
19
+ # Train the model
20
+ regressor = LinearRegression()
21
+ regressor.fit(X_train, y_train)
22
+
23
+ # Define the prediction function
24
+ def predict_stock_price(open_price, high_price, low_price, volume):
25
+ input_data = np.array([[open_price, high_price, low_price, volume]])
26
+ predicted_price = regressor.predict(input_data)[0]
27
+ return round(predicted_price, 2)
28
+
29
+ # Create the Gradio interface
30
+ iface = gr.Interface(
31
+ fn=predict_stock_price,
32
+ inputs=[
33
+ gr.Number(label="Opening Price"),
34
+ gr.Number(label="High Price"),
35
+ gr.Number(label="Low Price"),
36
+ gr.Number(label="Volume")
37
+ ],
38
+ outputs=gr.Text(label="Predicted Closing Price"),
39
+ title="Stock Price Prediction App",
40
+ description="Enter stock data to predict the closing price using a Linear Regression model."
41
+ )
42
+
43
+ # Run the Gradio app
44
+ if __name__ == "__main__":
45
+ iface.launch()