Spaces:
Runtime error
Runtime error
Update app.py
Browse files3 unmodified lines456789101112131415161718192021222324252627282930313233343536373839403 unmodified linesfrom datetime import datetime, timedeltaimport gradio as grdef fetch_data():end_date = datetime.now()start_date = end_date - timedelta(days=5 * 365)us_interest_rate_data = yf.download('^TNX', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))bnb_data = yf.download('BNB-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))return us_interest_rate_data['Close'], bnb_data['Close']def normalize_data(data):return (data - data.min()) / (data.max() - data.min())def plot_data(interest_rate_data, bnb_prices):# ๋ฐ์ดํฐ ๊ฒ์ฆif interest_rate_data.empty or bnb_prices.empty:print("Error: Input data is empty.")return None# ๋ฐ์ดํฐ ์ ๊ทํ ๋ฐ ์ฐจ์ด ๊ณ์ฐinterest_rate_normalized = normalize_data(interest_rate_data)bnb_normalized = normalize_data(bnb_prices)diff_normalized = normalize_data(bnb_normalized - interest_rate_normalized)# ๊ทธ๋ํ ์์ฑplt.figure(figsize=(14, 7))plt.plot(diff_normalized, color='green', label='Normalized Difference (BNB Price - US 10-Year Treasury Yield)')plt.axhline(y=0.5, color='black', linestyle='--')plt.title('Difference between Binance Coin Price and US 10-Year Treasury Yield')plt.xlabel('Date')plt.ylabel('Normalized Value')plt.legend()plt.grid(True)return plt.gcf()def run_app():3 unmodified lines45678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273743 unmodified linesfrom datetime import datetime, timedeltaimport gradio as grimport yfinance as yfimport pandas as pdimport matplotlib.pyplot as pltfrom datetime import datetime, timedelta# ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐdef fetch_data():end_date = datetime.now()start_date = end_date - timedelta(days=5 * 365)# ๋ฏธ๊ตญ์ 10๋ ๋ฌผ ๊ตญ์ฑ ์์ต๋ฅ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐus_interest_rate_data = yf.download('^TNX', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))us_interest_rate_daily = us_interest_rate_data['Close']# ๋นํธ์ฝ์ธ ๊ฐ๊ฒฉ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐbtc_data = yf.download('BTC-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))btc_daily = btc_data['Close']return us_interest_rate_daily, btc_daily# ๋ฐ์ดํฐ ์ ๊ทํdef normalize_data(data):return (data - data.min()) / (data.max() - data.min())# ๋ฐ์ดํฐ ๋ถ์ ๋ฐ ๊ทธ๋ํ ์์ฑdef plot_data(interest_rate_data, btc_prices):# ๋ฐ์ดํฐ ์ ๊ทํinterest_rate_normalized = normalize_data(interest_rate_data)btc_normalized = normalize_data(btc_prices)# ๋ ๋ฐ์ดํฐ์ ์ฐจ์ด ๊ณ์ฐ ๋ฐ ์ ๊ทํdiff_normalized = normalize_data(btc_normalized - interest_rate_normalized)# ๊ทธ๋ํ ์์ฑplt.figure(figsize=(14, 7))plt.plot(diff_normalized, color='green', label='Normalized Difference (Bitcoin Price - US 10-Year Treasury Yield)')plt.axhline(y=0.5, color='black', linestyle='--', label='Normalized Value: 0.5')# ๋ฐฐ๊ฒฝ์ ์ค์ plt.axhspan(0.0, 0.2, color='blue', alpha=0.3)plt.axhspan(0.2, 0.4, color='lightblue', alpha=0.3)plt.axhspan(0.4, 0.5, color='skyblue', alpha=0.3)plt.axhspan(0.5, 0.6, color='yellow', alpha=0.3)plt.axhspan(0.6, 0.8, color='orange', alpha=0.3)plt.axhspan(0.8, 1.0, color='red', alpha=0.3)# ํ์ฌ ์ ๊ทํ๋ ๊ฐ ํ์current_value = diff_normalized.iloc[-1]plt.text(len(diff_normalized) - 1, current_value, f'Normalized Value: {current_value:.3f}', verticalalignment='bottom', horizontalalignment='right')plt.title('Difference between Bitcoin Price and US 10-Year Treasury Yield')plt.xlabel('Date')plt.ylabel('Normalized Value')plt.legend()plt.grid(True)# ํ์ฌ Figure ๊ฐ์ฒด๋ฅผ ๋ฐํํ๊ณ ํ์ํ์ง ์์fig = plt.gcf() # Get the current figure before plt.show()plt.close() # Close the plot to free up memoryreturn figif __name__ == "__main__":interest_rate_data, btc_prices = fetch_data()fig = plot_data(interest_rate_data, btc_prices)# ์ฌ๊ธฐ์ fig ๊ฐ์ฒด๋ฅผ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ๋ฌํ๊ฑฐ๋, ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ํ์ฉํ ์ ์์ต๋๋ค.def run_app():
app.py+49-15