Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines345678910111213141516171819202 unmodified linesimport numpy as npimport timedef live_chart():# ์๊ฐ ๊ธฐ๋ฐ ๋ฐ์ดํฐ ์์ฑt = np.linspace(0, 2 * np.pi, 100)y = np.sin(t + time.time()) # ์๊ฐ์ ๋ฐ๋ผ ๋ณํํ๋ ๊ทธ๋ํplt.figure(figsize=(10, 5))plt.plot(t, y)plt.title("Real-time Sine Wave")plt.xlabel("Time")plt.ylabel("Amplitude")plt.grid(True)plt.close()return pltiface = gr.Interface(fn=live_chart, inputs=[], outputs="plot", live=True, title="Live Sine Wave Chart")iface.launch()2 unmodified lines34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465662 unmodified linesimport numpy as npimport timeimport 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']# ๋ฐ์ด๋ธ์ค ์ฝ์ธ ๊ฐ๊ฒฉ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐbnb_data = yf.download('BNB-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))bnb_daily = bnb_data['Close']return us_interest_rate_daily, bnb_daily# ๋ฐ์ดํฐ ์ ๊ทํdef normalize_data(data):return (data - data.min()) / (data.max() - data.min())# ๋ฐ์ดํฐ ๋ถ์ ๋ฐ ๊ทธ๋ํ ์์ฑdef plot_data(interest_rate_data, bnb_prices):# ๋ฐ์ดํฐ ์ ๊ทํinterest_rate_normalized = normalize_data(interest_rate_data)bnb_normalized = normalize_data(bnb_prices)# ๋ ๋ฐ์ดํฐ์ ์ฐจ์ด ๊ณ์ฐ ๋ฐ ์ ๊ทํdiff_normalized = normalize_data(bnb_normalized - interest_rate_normalized)# ๊ฒ์์ ์ ์ ๊ทธ๋ฆด ๊ตฌ๊ฐ ์ค์ threshold = 0.5plt.figure(figsize=(14, 7))plt.plot(diff_normalized, color='green', label='Normalized Difference (Binance Coin Price - US 10-Year Treasury Yield)')# ๊ฒ์์ ์ ์ ๊ทธ๋ฆด ๊ตฌ๊ฐ ์ค์ plt.axhline(y=threshold, color='black', linestyle='--', label=f'Normalized Value: {threshold}')# ๋ฐฐ๊ฒฝ์ ์ค์ 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)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)plt.show()if __name__ == "__main__":interest_rate_data, bnb_prices = fetch_data()plot_data(interest_rate_data, bnb_prices)iface = gr.Interface(fn=live_chart, inputs=[], outputs="plot", live=True, title="Live Sine Wave Chart")iface.launch()
app.py+57-11