llllllllllllllllllllllllllleeeeeeeeeeeeee
commited on
Commit
โข
467f517
1
Parent(s):
8a6cb56
Update app.py
Browse files
app.py
CHANGED
@@ -79,10 +79,10 @@ def get_real_news_summary(company, date):
|
|
79 |
# OpenAI ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
80 |
client = OpenAI(api_key=API_KEY, base_url="https://api.perplexity.ai")
|
81 |
|
82 |
-
# API ์์ฒญ์ ์ํ ๋ฉ์์ง ๊ตฌ์ฑ
|
83 |
messages = [
|
84 |
-
{"role": "system", "content": "You are a helpful assistant that summarizes stock news in Korean."},
|
85 |
-
{"role": "user", "content": f"Summarize the latest stock news for {company} on {date} in Korean. If there's no specific news for that date, provide the most recent relevant information."}
|
86 |
]
|
87 |
|
88 |
try:
|
@@ -98,7 +98,10 @@ def get_real_news_summary(company, date):
|
|
98 |
# ํ๊ธ, ์ซ์, ๊ณต๋ฐฑ, ํน์ ๊ธฐํธ๋ง ๋จ๊ธฐ๋ ์ ๊ท ํํ์
|
99 |
korean_only_summary = re.sub(r'[^\w\s#.,!%()-]', '', summary)
|
100 |
|
101 |
-
|
|
|
|
|
|
|
102 |
except Exception as e:
|
103 |
return f"๋ด์ค ์์ฝ ์ค ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
104 |
|
@@ -106,19 +109,19 @@ def get_real_news_summary(company, date):
|
|
106 |
def handle_click(input_value, date_clicked):
|
107 |
return get_real_news_summary(input_value, date_clicked)
|
108 |
|
109 |
-
#
|
110 |
-
def update_news(input_value, selected_date):
|
111 |
-
if selected_date == "" or selected_date is None:
|
112 |
-
return "๋ ์ง๋ฅผ ์ ํํด์ฃผ์ธ์."
|
113 |
-
else:
|
114 |
-
return handle_click(input_value, selected_date)
|
115 |
-
|
116 |
-
# ์ข
๋ชฉ๋ช
๊ณผ ํฐ์ปค๋ฅผ ๋งคํํ๋ ๋์
๋๋ฆฌ
|
117 |
name_to_ticker = {
|
118 |
"์ผ์ฑ์ ์": "005930.KS",
|
119 |
"SK๋ฐ์ด์คํ": "326030.KS",
|
120 |
"Apple": "AAPL",
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
|
124 |
# ์ฃผ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์กฐ๊ฑด์ ๋ง๋ ๋ ์ง์ ๊ทธ๋ํ๋ฅผ ๋ฐํํ๋ ํจ์
|
@@ -174,7 +177,7 @@ def display_stock_with_highlight(input_value, change_type, percent_change):
|
|
174 |
|
175 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ (3์ด ๋ ์ด์์)
|
176 |
with gr.Blocks() as demo:
|
177 |
-
gr.Markdown("
|
178 |
|
179 |
with gr.Row():
|
180 |
with gr.Column(): # ์
๋ ฅ๊ฐ์ ๋ด์ ์ฒซ ๋ฒ์งธ ์ด
|
@@ -198,7 +201,8 @@ with gr.Blocks() as demo:
|
|
198 |
date_dropdown = gr.Dropdown(label="์กฐ๊ฑด์ ํด๋นํ๋ ๋ ์ง ์ ํ", choices=[])
|
199 |
|
200 |
with gr.Column(): # ๋ด์ค ์์ฝ์ ์ถ๋ ฅํ ์ธ ๋ฒ์งธ ์ด
|
201 |
-
news_output
|
|
|
202 |
|
203 |
# Submit ๋ฒํผ ํด๋ฆญ ์ ๊ทธ๋ํ ๋ฐ ๋ ์ง ๋๋กญ๋ค์ด ์
๋ฐ์ดํธ
|
204 |
submit_btn.click(
|
|
|
79 |
# OpenAI ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
80 |
client = OpenAI(api_key=API_KEY, base_url="https://api.perplexity.ai")
|
81 |
|
82 |
+
# API ์์ฒญ์ ์ํ ๋ฉ์์ง ๊ตฌ์ฑ - ํ๊ตญ์ด๋ก๋ง ์๋ต์ ๋ฐ๋๋ก ์ง์
|
83 |
messages = [
|
84 |
+
{"role": "system", "content": "You are a helpful assistant that summarizes stock news strictly in Korean."},
|
85 |
+
{"role": "user", "content": f"Summarize the latest stock news for {company} on {date} in Korean. If there's no specific news for that date, provide the most recent relevant information in Korean."}
|
86 |
]
|
87 |
|
88 |
try:
|
|
|
98 |
# ํ๊ธ, ์ซ์, ๊ณต๋ฐฑ, ํน์ ๊ธฐํธ๋ง ๋จ๊ธฐ๋ ์ ๊ท ํํ์
|
99 |
korean_only_summary = re.sub(r'[^\w\s#.,!%()-]', '', summary)
|
100 |
|
101 |
+
# ##๋ก ์์ํ๋ ๋ถ๋ถ์ **์ผ๋ก ๊ฐ์ธ์ Bold ์ฒ๋ฆฌ
|
102 |
+
formatted_summary = re.sub(r'##\s*(.+)', r'**\1**', korean_only_summary)
|
103 |
+
|
104 |
+
return formatted_summary
|
105 |
except Exception as e:
|
106 |
return f"๋ด์ค ์์ฝ ์ค ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
107 |
|
|
|
109 |
def handle_click(input_value, date_clicked):
|
110 |
return get_real_news_summary(input_value, date_clicked)
|
111 |
|
112 |
+
# ์ข
๋ชฉ๋ช
๊ณผ ํฐ์ปค๋ฅผ ๋งคํํ๋ ๋์
๋๋ฆฌ ํ์ฅ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
name_to_ticker = {
|
114 |
"์ผ์ฑ์ ์": "005930.KS",
|
115 |
"SK๋ฐ์ด์คํ": "326030.KS",
|
116 |
"Apple": "AAPL",
|
117 |
+
"Nvidia": "NVDA",
|
118 |
+
"Vertex": "VRTX",
|
119 |
+
"ํ๋์ฐจ": "005380.KS",
|
120 |
+
"์นด์นด์ค": "035720.KS",
|
121 |
+
"LGํํ": "051910.KS",
|
122 |
+
"์
ํธ๋ฆฌ์จ": "068270.KS",
|
123 |
+
"๋ค์ด๋ฒ": "035420.KS",
|
124 |
+
# ์ถ๊ฐ๋ก ํ์ํ ์ข
๋ชฉ๋ค์ ์ฌ๊ธฐ์ ๊ณ์ ์ถ๊ฐํ์ธ์
|
125 |
}
|
126 |
|
127 |
# ์ฃผ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์กฐ๊ฑด์ ๋ง๋ ๋ ์ง์ ๊ทธ๋ํ๋ฅผ ๋ฐํํ๋ ํจ์
|
|
|
177 |
|
178 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ (3์ด ๋ ์ด์์)
|
179 |
with gr.Blocks() as demo:
|
180 |
+
gr.Markdown("## ์ฃผ๊ฐ ๊ทธ๋ํ์ ๋ด์ค ์์ฝ")
|
181 |
|
182 |
with gr.Row():
|
183 |
with gr.Column(): # ์
๋ ฅ๊ฐ์ ๋ด์ ์ฒซ ๋ฒ์งธ ์ด
|
|
|
201 |
date_dropdown = gr.Dropdown(label="์กฐ๊ฑด์ ํด๋นํ๋ ๋ ์ง ์ ํ", choices=[])
|
202 |
|
203 |
with gr.Column(): # ๋ด์ค ์์ฝ์ ์ถ๋ ฅํ ์ธ ๋ฒ์งธ ์ด
|
204 |
+
# news_output์ gr.Markdown์ผ๋ก ๋ณ๊ฒฝ
|
205 |
+
news_output = gr.Markdown(label="๋ด์ค ์์ฝ")
|
206 |
|
207 |
# Submit ๋ฒํผ ํด๋ฆญ ์ ๊ทธ๋ํ ๋ฐ ๋ ์ง ๋๋กญ๋ค์ด ์
๋ฐ์ดํธ
|
208 |
submit_btn.click(
|