Commit
c9c1f74
ยท
verified ยท
1 Parent(s): 9bde65d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -61,16 +61,8 @@ plt.legend(prop=font_prop)
61
 
62
  # B ์ฝ”๋“œ
63
 
64
- # ์ดํ›„ ์ฝ”๋“œ ์‹คํ–‰
65
- import requests
66
- import gradio as gr
67
- import io
68
- from PIL import Image
69
- from datetime import datetime, timedelta
70
- from openai import OpenAI
71
-
72
  # Perplexity AI API ์„ค์ •
73
- API_KEY = "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" # ์—ฌ๊ธฐ์— Perplexity AI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
74
 
75
  # ๋‰ด์Šค ์š”์•ฝ์„ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜
76
  def get_real_news_summary(company, date):
@@ -104,15 +96,18 @@ def get_real_news_summary(company, date):
104
  return f"๋‰ด์Šค ์š”์•ฝ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
105
 
106
  # ๋‰ด์Šค ์š”์•ฝ์„ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜
107
- def handle_click(input_value, date_clicked):
108
- return get_real_news_summary(input_value, date_clicked)
109
 
110
  # Gradio์—์„œ ์‚ฌ์šฉํ•  ํ•จ์ˆ˜ (๋‰ด์Šค ์š”์•ฝ ํฌํ•จ)
111
  def update_news(input_value, selected_date):
112
  if selected_date == "" or selected_date is None:
113
  return "๋‚ ์งœ๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”."
114
  else:
115
- return handle_click(input_value, selected_date)
 
 
 
116
 
117
  # ์ข…๋ชฉ๋ช…๊ณผ ํ‹ฐ์ปค๋ฅผ ๋งคํ•‘ํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ ํ™•์žฅ ๋ฐ ์กฐ๊ฑด๋ณ„ ์ข…๋ชฉ ๋งคํ•‘
118
  name_to_ticker = {
@@ -168,9 +163,10 @@ def display_stock_with_highlight(input_value, change_type, percent_change):
168
  plt.text(index, row['Close'], index.strftime('%Y-%m-%d'), fontsize=10, fontweight='bold', color=color, ha='right')
169
  plt.axvline(x=index, color=color, linestyle='--', linewidth=1) # x์ถ•๊ณผ์˜ ์—ฐ๊ฒฐ์„  ์ ์„ ์œผ๋กœ ํ‘œ์‹œ
170
 
171
- plt.title(f'{input_value} ์ฃผ๊ฐ€ ์ถ”์ด ({change_type} ํ‘œ์‹œ)')
172
- plt.xlabel('๋‚ ์งœ')
173
- plt.ylabel('์ข…๊ฐ€')
 
174
  plt.legend()
175
 
176
  buf = io.BytesIO()
 
61
 
62
  # B ์ฝ”๋“œ
63
 
 
 
 
 
 
 
 
 
64
  # Perplexity AI API ์„ค์ •
65
+ API_KEY = "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" # ์—ฌ๊ธฐ์— Perplexity AI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
66
 
67
  # ๋‰ด์Šค ์š”์•ฝ์„ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜
68
  def get_real_news_summary(company, date):
 
96
  return f"๋‰ด์Šค ์š”์•ฝ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
97
 
98
  # ๋‰ด์Šค ์š”์•ฝ์„ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜
99
+ def handle_click(company_name, date_clicked):
100
+ return get_real_news_summary(company_name, date_clicked)
101
 
102
  # Gradio์—์„œ ์‚ฌ์šฉํ•  ํ•จ์ˆ˜ (๋‰ด์Šค ์š”์•ฝ ํฌํ•จ)
103
  def update_news(input_value, selected_date):
104
  if selected_date == "" or selected_date is None:
105
  return "๋‚ ์งœ๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”."
106
  else:
107
+ # ์ข…๋ชฉ๋ช…์„ ๊ฐ€์ ธ์™€์„œ Perplexity๋กœ ๊ฒ€์ƒ‰
108
+ ticker = name_to_ticker.get(input_value, input_value)
109
+ company_name = input_value if ticker == input_value else list(name_to_ticker.keys())[list(name_to_ticker.values()).index(ticker)]
110
+ return handle_click(company_name, selected_date)
111
 
112
  # ์ข…๋ชฉ๋ช…๊ณผ ํ‹ฐ์ปค๋ฅผ ๋งคํ•‘ํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ ํ™•์žฅ ๋ฐ ์กฐ๊ฑด๋ณ„ ์ข…๋ชฉ ๋งคํ•‘
113
  name_to_ticker = {
 
163
  plt.text(index, row['Close'], index.strftime('%Y-%m-%d'), fontsize=10, fontweight='bold', color=color, ha='right')
164
  plt.axvline(x=index, color=color, linestyle='--', linewidth=1) # x์ถ•๊ณผ์˜ ์—ฐ๊ฒฐ์„  ์ ์„ ์œผ๋กœ ํ‘œ์‹œ
165
 
166
+ # ์ข…๋ชฉ๋ช… + '์ฃผ๊ฐ€ ์ถ”์ด'๋กœ ์ œ๋ชฉ ์„ค์ •
167
+ plt.title(f'{input_value} ์ฃผ๊ฐ€ ์ถ”์ด', fontproperties=font_prop)
168
+ plt.xlabel('๋‚ ์งœ', fontproperties=font_prop)
169
+ plt.ylabel('์ข…๊ฐ€', fontproperties=font_prop)
170
  plt.legend()
171
 
172
  buf = io.BytesIO()