Update app.py
Browse files
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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"
|
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(
|
108 |
-
return get_real_news_summary(
|
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 |
-
|
|
|
|
|
|
|
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 |
-
|
172 |
-
plt.
|
173 |
-
plt.
|
|
|
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()
|