Commit
467f517
โ€ข
1 Parent(s): 8a6cb56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
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
- return korean_only_summary
 
 
 
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
- # Gradio์—์„œ ์‚ฌ์šฉํ•  ํ•จ์ˆ˜ (๋‰ด์Šค ์š”์•ฝ ํฌํ•จ)
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 = gr.Textbox(label="๋‰ด์Šค ์š”์•ฝ")
 
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(