Sukhmanpreet commited on
Commit
c2af349
·
verified ·
1 Parent(s): 8300405

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +55 -0
  2. model.pkl +3 -0
  3. requirements.txt +4 -0
  4. stocks price prediction.ipynb +0 -0
  5. yahoo_data.xlsx +0 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pickle
4
+
5
+ # Function to load the model from pickle
6
+ def load_model(path):
7
+ with open(path, 'rb') as f:
8
+ model = pickle.load(f)
9
+ return model
10
+
11
+ # Define the main function for predicting stock price
12
+ def predict_stock_price(open_val, high_val, low_val, close_val, adj_close_val, volume, model):
13
+ try:
14
+ # Prepare the input data as a numpy array
15
+ X = np.array([[open_val, high_val, low_val, close_val, adj_close_val]])
16
+
17
+ # Use the loaded model for prediction
18
+ predicted_price = model.predict(X)
19
+
20
+ return predicted_price[0]
21
+ except (ValueError, AttributeError) as e:
22
+ st.error(f'Error occurred: {str(e)}')
23
+ return None
24
+
25
+ # Define the Streamlit app
26
+ def main():
27
+ st.title('Stock Prediction')
28
+
29
+ # Load your trained model from pickle
30
+ model_path = 'model.pkl' # Replace with your actual path
31
+ model = load_model(model_path)
32
+
33
+ # Input fields for user to enter stock data
34
+ open_val = st.number_input('Open (Range: 0 to 100000)', min_value=0.0, max_value=100000.0, value=0.0)
35
+ high_val = st.number_input('High (Range: 0 to 100000)', min_value=0.0, max_value=100000.0, value=0.0)
36
+ low_val = st.number_input('Low (Range: 0 to 100000)', min_value=0.0, max_value=100000.0, value=0.0)
37
+ close_val = st.number_input('Close* (Range: 0 to 100000)', min_value=0.0, max_value=100000.0, value=0.0)
38
+ adj_close_val = st.number_input('Adj Close** (Range: 0 to 100000)', min_value=0.0, max_value=100000.0, value=0.0)
39
+ volume = st.number_input('Volume (Range: 0 to 1,000,000,000)', min_value=0.0, max_value=1000000000.0, value=0.0)
40
+
41
+ # Predict button
42
+ if st.button('Predict'):
43
+ if any([open_val == 0.0, high_val == 0.0, low_val == 0.0, close_val == 0.0, adj_close_val == 0.0, volume == 0.0]):
44
+ st.error('Please enter valid numeric values for all fields.')
45
+ else:
46
+ # Call prediction function
47
+ predicted_price = predict_stock_price(open_val, high_val, low_val, close_val, adj_close_val, volume, model)
48
+
49
+ if predicted_price is not None:
50
+ st.success(f'The predicted stock price is: {predicted_price:.2f}')
51
+ else:
52
+ st.error('Failed to predict stock price.')
53
+
54
+ if __name__ == '__main__':
55
+ main()
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41da2ec13c1ba813e5dc65951ca56417c0e5ec419115b0021a425d31d25a44d2
3
+ size 613
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pandas
2
+ scikit-learn
3
+ numpy
4
+ streamlit
stocks price prediction.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
yahoo_data.xlsx ADDED
Binary file (82.5 kB). View file