Spaces:
Runtime error
Runtime error
Download app.py from el3afreeet/Quantum: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/el3afreeet/Quantum/resolve/main/app.py
- Command line
-
hf download hf://spaces/el3afreeet/Quantum/app.py
-
curl -L -o app.py https://huggingface.co/spaces/el3afreeet/Quantum/resolve/main/app.py
1.29 kB
| !pip install gradio yfinance keras tensorflow | |
| import gradio as gr | |
| import yfinance as yf | |
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow.keras.models import Sequential | |
| from tensorflow.keras.layers import Dense, LSTM | |
| import datetime | |
| def fetch_data(symbol="EURUSD=X"): | |
| end = datetime.datetime.now() | |
| start = end - datetime.timedelta(days=100) | |
| data = yf.download(symbol, start=start, end=end, interval='1h') | |
| return data['Close'].values[-60:] | |
| def train_model(data): | |
| X, y = [], [] | |
| for i in range(len(data)-10): | |
| X.append(data[i:i+10]) | |
| y.append(data[i+10]) | |
| X = np.array(X).reshape(-1, 10, 1) | |
| y = np.array(y) | |
| model = Sequential([ | |
| LSTM(50, return_sequences=False, input_shape=(10,1)), | |
| Dense(1) | |
| ]) | |
| model.compile(loss='mse', optimizer='adam') | |
| model.fit(X, y, epochs=5, verbose=0) | |
| return model | |
| def predict(): | |
| data = fetch_data() | |
| model = train_model(data) | |
| input_seq = np.array(data[-10:]).reshape(1,10,1) | |
| prediction = model.predict(input_seq)[0][0] | |
| return f"التوصية: {'شراء' if prediction > data[-1] else 'بيع'}\nالسعر المتوقع: {prediction:.5f}" | |
| iface = gr.Interface(fn=predict, inputs=[], outputs="text", title="AI توصيات فوركس") | |
| iface.launch() |