Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,13 @@ import subprocess
|
|
4 |
subprocess.run(["pip", "install", "--upgrade", "pip"])
|
5 |
subprocess.run(["pip", "install", "--upgrade", "openai", "yfinance", "gradio", "matplotlib", "Pillow"])
|
6 |
|
7 |
-
# gradio ์ค์น ํ ์ํฌํธ
|
8 |
import os
|
9 |
import matplotlib.font_manager as fm
|
10 |
import matplotlib.pyplot as plt
|
11 |
import yfinance as yf
|
12 |
import numpy as np
|
13 |
import re # ํ๊ธ, ์ซ์, ๊ธฐํธ๋ฅผ ๋จ๊ธฐ๊ธฐ ์ํ ์ ๊ท ํํ์์ ์ฌ์ฉ
|
14 |
-
import gradio as gr
|
15 |
|
16 |
# 1. ๋๋๊ณ ๋ ํฐํธ ์ค์น ๋ฐ ์ ์ฉ
|
17 |
def install_nanum_font():
|
@@ -37,31 +36,31 @@ font_prop = fm.FontProperties(fname=font_path)
|
|
37 |
plt.rcParams['font.family'] = font_prop.get_name()
|
38 |
plt.rcParams['axes.unicode_minus'] = False # ๋ง์ด๋์ค ๋ถํธ ๊นจ์ง ๋ฐฉ์ง
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
|
66 |
# Perplexity AI API ์ค์
|
67 |
API_KEY = "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" # ์ฌ๊ธฐ์ Perplexity AI API ํค๋ฅผ ์
๋ ฅํ์ธ์.
|
@@ -111,30 +110,22 @@ def update_news(input_value, selected_date):
|
|
111 |
company_name = input_value if ticker == input_value else list(name_to_ticker.keys())[list(name_to_ticker.values()).index(ticker)]
|
112 |
return handle_click(company_name, selected_date)
|
113 |
|
114 |
-
# ์ข
๋ชฉ๋ช
๊ณผ ํฐ์ปค๋ฅผ
|
115 |
-
|
116 |
-
"
|
117 |
-
|
118 |
-
"
|
119 |
-
|
120 |
-
"
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
"์
ํธ๋ฆฌ์จ": "068270.KS",
|
125 |
-
"๋ค์ด๋ฒ": "035420.KS",
|
126 |
-
"๋์ค๋ฅ ์์ด 1์": "AAPL", # Apple
|
127 |
-
"๋์ค๋ฅ ๋ฐ์ด์คํ
์์ด 1์": "VRTX", # Vertex Pharmaceuticals
|
128 |
-
"๋์ค๋ฅ ์ ์ฝ์ฃผ ์์ด 1์": "VRTX", # Vertex Pharmaceuticals
|
129 |
-
"์ฝ์คํผ ์์ด 1์": "005930.KS", # ์ผ์ฑ์ ์
|
130 |
-
"์ฝ์ค๋ฅ ์์ด 1์": "035420.KS", # ๋ค์ด๋ฒ
|
131 |
-
}
|
132 |
|
133 |
# ์ฃผ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์กฐ๊ฑด์ ๋ง๋ ๋ ์ง์ ๊ทธ๋ํ๋ฅผ ๋ฐํํ๋ ํจ์
|
134 |
def display_stock_with_highlight(input_value, change_type, percent_change):
|
135 |
try:
|
136 |
# ์
๋ ฅ๊ฐ์ ํฐ์ปค๋ก ๋ณํ
|
137 |
-
ticker =
|
138 |
stock = yf.Ticker(ticker)
|
139 |
stock_data = stock.history(period="5y") # ์ต๊ทผ 5๋
๋ฐ์ดํฐ๋ก ์ ํ
|
140 |
|
|
|
4 |
subprocess.run(["pip", "install", "--upgrade", "pip"])
|
5 |
subprocess.run(["pip", "install", "--upgrade", "openai", "yfinance", "gradio", "matplotlib", "Pillow"])
|
6 |
|
|
|
7 |
import os
|
8 |
import matplotlib.font_manager as fm
|
9 |
import matplotlib.pyplot as plt
|
10 |
import yfinance as yf
|
11 |
import numpy as np
|
12 |
import re # ํ๊ธ, ์ซ์, ๊ธฐํธ๋ฅผ ๋จ๊ธฐ๊ธฐ ์ํ ์ ๊ท ํํ์์ ์ฌ์ฉ
|
13 |
+
import gradio as gr
|
14 |
|
15 |
# 1. ๋๋๊ณ ๋ ํฐํธ ์ค์น ๋ฐ ์ ์ฉ
|
16 |
def install_nanum_font():
|
|
|
36 |
plt.rcParams['font.family'] = font_prop.get_name()
|
37 |
plt.rcParams['axes.unicode_minus'] = False # ๋ง์ด๋์ค ๋ถํธ ๊นจ์ง ๋ฐฉ์ง
|
38 |
|
39 |
+
# ์๊ฐ์ด์ก ๊ธฐ์ค์ผ๋ก ์ข
๋ชฉ ๊ฒ์
|
40 |
+
def get_top_market_cap_stock(market):
|
41 |
+
if market == "์ฝ์ค๋ฅ":
|
42 |
+
# ์ฝ์ค๋ฅ ์์ฅ ์ข
๋ชฉ ๊ฒ์
|
43 |
+
tickers = yf.Tickers('^KQ11') # ์ฝ์ค๋ฅ ์์ ์ข
๋ชฉ๋ค์ ์ป์ด์ค๊ธฐ ์ํ ์งํ
|
44 |
+
elif market == "์ฝ์คํผ":
|
45 |
+
tickers = yf.Tickers('^KS11') # ์ฝ์คํผ ์์ ์ข
๋ชฉ๋ค
|
46 |
+
else:
|
47 |
+
tickers = yf.Tickers('^IXIC') # ๋์ค๋ฅ ์์ ์ข
๋ชฉ๋ค
|
48 |
+
|
49 |
+
stock_list = tickers.tickers
|
50 |
+
top_stock = None
|
51 |
+
top_market_cap = 0
|
52 |
+
|
53 |
+
for stock in stock_list:
|
54 |
+
try:
|
55 |
+
stock_info = stock.info
|
56 |
+
market_cap = stock_info.get('marketCap', 0)
|
57 |
+
if market_cap > top_market_cap:
|
58 |
+
top_market_cap = market_cap
|
59 |
+
top_stock = stock_info.get('symbol', None)
|
60 |
+
except:
|
61 |
+
continue
|
62 |
+
|
63 |
+
return top_stock
|
64 |
|
65 |
# Perplexity AI API ์ค์
|
66 |
API_KEY = "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" # ์ฌ๊ธฐ์ Perplexity AI API ํค๋ฅผ ์
๋ ฅํ์ธ์.
|
|
|
110 |
company_name = input_value if ticker == input_value else list(name_to_ticker.keys())[list(name_to_ticker.values()).index(ticker)]
|
111 |
return handle_click(company_name, selected_date)
|
112 |
|
113 |
+
# ์ข
๋ชฉ๋ช
๊ณผ ํฐ์ปค๋ฅผ ๋์ ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ํ ํจ์
|
114 |
+
def get_dynamic_ticker(input_value):
|
115 |
+
if input_value == "๋์ค๋ฅ ์์ด 1์":
|
116 |
+
return get_top_market_cap_stock("๋์ค๋ฅ")
|
117 |
+
elif input_value == "์ฝ์คํผ ์์ด 1์":
|
118 |
+
return get_top_market_cap_stock("์ฝ์คํผ")
|
119 |
+
elif input_value == "์ฝ์ค๋ฅ ์์ด 1์":
|
120 |
+
return get_top_market_cap_stock("์ฝ์ค๋ฅ")
|
121 |
+
else:
|
122 |
+
return name_to_ticker.get(input_value, input_value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
# ์ฃผ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์กฐ๊ฑด์ ๋ง๋ ๋ ์ง์ ๊ทธ๋ํ๋ฅผ ๋ฐํํ๋ ํจ์
|
125 |
def display_stock_with_highlight(input_value, change_type, percent_change):
|
126 |
try:
|
127 |
# ์
๋ ฅ๊ฐ์ ํฐ์ปค๋ก ๋ณํ
|
128 |
+
ticker = get_dynamic_ticker(input_value)
|
129 |
stock = yf.Ticker(ticker)
|
130 |
stock_data = stock.history(period="5y") # ์ต๊ทผ 5๋
๋ฐ์ดํฐ๋ก ์ ํ
|
131 |
|