Download app.py from Pezh/ped: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/spaces/Pezh/ped/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pezh/ped/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pezh/ped/resolve/main/app.py
2.5 kB
| import telebot | |
| import random | |
| import yfinance as yf | |
| import pandas as pd | |
| import numpy as np | |
| from xgboost import XGBRegressor | |
| from sklearn.metrics import mean_squared_error | |
| from sklearn.model_selection import train_test_split | |
| from math import sqrt | |
| import streamlit as st | |
| text_input = st.text_input('نیوی ارزکه وارد که کوزت؛ وکو BTC-USD :') | |
| # Fetch historical data for BTC-USD | |
| if text_input: | |
| data = yf.download(text_input, period='max')#start="2019-01-01", end="2023-12-28") | |
| #data = yf.download(text_input, start="2010-01-01", end=pd.to_datetime('today').date()) | |
| # Select Open and Close price | |
| data = data[['Open', 'Close']] | |
| #print(data) | |
| # Create a new "lagged" dataframe for the model | |
| data['Previous_Close'] = data['Close'].shift(1) | |
| # Drop the missing values created by shifting | |
| data = data.dropna() | |
| # Define inputs and outputs | |
| X = data['Previous_Close'].values.reshape(-1, 1) | |
| y = data['Close'].values | |
| # Split the data into training and testing datasets | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| # Initialize XGBoost regressor model | |
| model = XGBRegressor(n_estimators=100, learning_rate=0.1, objective='reg:squarederror') | |
| # Train the model | |
| model.fit(X_train, y_train) | |
| # Evaluate the model | |
| train_predictions = model.predict(X_train) | |
| train_rmse = sqrt(mean_squared_error(y_train, train_predictions)) | |
| #print(f"Train RMSE: {train_rmse}") | |
| test_predictions = model.predict(X_test) | |
| test_rmse = sqrt(mean_squared_error(y_test, test_predictions)) | |
| #print(f"Test RMSE: {test_rmse}") | |
| # Predict tomorrow's close price using the most recent close price | |
| latest_close = data['Close'].iloc[-1] | |
| # Reshape the input | |
| latest_close_reshaped = np.array(latest_close).reshape(1, -1) | |
| # Make prediction | |
| predicted_close = model.predict(latest_close_reshaped) | |
| if st.button('say'): | |
| #st.write(type(predicted_close[0])) | |
| st.write(data) | |
| #mylist = [-0/035, -0/024, 0/03, 0/032] | |
| #mylist = [-0.035, -0.024, 0.028, 0.03] | |
| if st.button('PediCrypto'): | |
| st.write('کمی بیسه کوزت') | |
| st.write(predicted_close[0]) | |
| st.write(latest_close) | |
| #st.write(int(predicted_close[0])) + (random.choice(mylist) * int(predicted_close[0]))) | |
| if st.button('Accuracy'): | |
| st.write(100-(test_rmse/100)) | |
| st.write('Powered by kapezhmanikhoman bo Pedram kozzet') |