Sonia2k5 commited on
Commit
54389ae
·
verified ·
1 Parent(s): 93bf804

Delete app .py

Browse files
Files changed (1) hide show
  1. app .py +0 -77
app .py DELETED
@@ -1,77 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """app.ipynb
3
-
4
- Automatically generated by Colab.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1vvN4x-mEuGtdgL2zlzu2ci6sercypfCa
8
- """
9
-
10
- import numpy as np
11
- import pandas as pd
12
- import gradio as gr
13
- from keras.models import Sequential
14
- from keras.layers import SimpleRNN, Dense
15
- from sklearn.preprocessing import MinMaxScaler
16
-
17
- # Generate dummy stock price data
18
- def generate_dummy_data():
19
- np.random.seed(0)
20
- time_steps = 100
21
- x = np.linspace(0, 20, time_steps)
22
- prices = 50 + np.sin(x) * 10 + np.random.normal(0, 1, time_steps)
23
- return prices
24
-
25
- # Preprocess data
26
- def prepare_data(data, window_size):
27
- X, y = [], []
28
- for i in range(len(data) - window_size):
29
- X.append(data[i:i + window_size])
30
- y.append(data[i + window_size])
31
- return np.array(X), np.array(y)
32
-
33
- # Create and train RNN model
34
- def train_model():
35
- raw_prices = generate_dummy_data().reshape(-1, 1)
36
- scaler = MinMaxScaler()
37
- scaled_prices = scaler.fit_transform(raw_prices)
38
-
39
- window_size = 5
40
- X, y = prepare_data(scaled_prices, window_size)
41
- X = X.reshape((X.shape[0], X.shape[1], 1))
42
-
43
- model = Sequential([
44
- SimpleRNN(50, activation='relu', input_shape=(window_size, 1)),
45
- Dense(1)
46
- ])
47
-
48
- model.compile(optimizer='adam', loss='mse')
49
- model.fit(X, y, epochs=30, verbose=0)
50
-
51
- return model, scaler, window_size
52
-
53
- model, scaler, window_size = train_model()
54
-
55
- # Prediction function for Gradio
56
- def predict_next_prices(inputs):
57
- inputs = [float(i) for i in inputs.split(',')]
58
- if len(inputs) != window_size:
59
- return f"Please enter {window_size} comma-separated values."
60
-
61
- input_array = np.array(inputs).reshape(-1, 1)
62
- scaled_input = scaler.transform(input_array).reshape((1, window_size, 1))
63
- scaled_prediction = model.predict(scaled_input)[0][0]
64
- predicted_price = scaler.inverse_transform([[scaled_prediction]])[0][0]
65
- return f"Predicted Next Price: ₹{predicted_price:.2f}"
66
-
67
- # Gradio Interface
68
- demo = gr.Interface(
69
- fn=predict_next_prices,
70
- inputs=gr.Textbox(label=f"Enter last {window_size} stock prices (comma-separated)"),
71
- outputs="text",
72
- title="RNN Stock Price Predictor (Dummy Data)",
73
- description="Enter previous prices to predict the next value."
74
- )
75
-
76
- if __name__ == "__main__":
77
- demo.launch()