Commit
2bdbf95
ยท
verified ยท
1 Parent(s): cc76dd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -3
app.py CHANGED
@@ -4,6 +4,62 @@ import subprocess
4
  subprocess.run(["pip", "install", "--upgrade", "pip"])
5
  subprocess.run(["pip", "install", "--upgrade", "openai", "yfinance", "gradio", "matplotlib", "Pillow"])
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # ์ดํ›„ ์ฝ”๋“œ ์‹คํ–‰
8
  import requests
9
  import gradio as gr
@@ -13,10 +69,9 @@ import io
13
  from PIL import Image
14
  from datetime import datetime, timedelta
15
  from openai import OpenAI
16
- import os
17
 
18
  # Perplexity AI API ์„ค์ •
19
- API_KEY = "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" # ์—ฌ๊ธฐ์— Perplexity AI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
20
 
21
  def get_real_news_summary(company, date):
22
  # OpenAI ํด๋ผ์ด์–ธํŠธ ์ดˆ๊ธฐํ™”
@@ -154,4 +209,4 @@ with gr.Blocks() as demo:
154
  )
155
 
156
  # Gradio ์‹คํ–‰
157
- demo.launch()
 
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
+
13
+ # 1. ๋‚˜๋ˆ”๊ณ ๋”• ํฐํŠธ ์„ค์น˜ ๋ฐ ์ ์šฉ
14
+ def install_nanum_font():
15
+ try:
16
+ subprocess.run(["apt-get", "update"], check=True)
17
+ subprocess.run(["apt-get", "install", "-y", "fonts-nanum"], check=True)
18
+ subprocess.run(["fc-cache", "-fv"], check=True)
19
+ except Exception as e:
20
+ print(f"ํฐํŠธ ์„ค์น˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {e}")
21
+
22
+ install_nanum_font()
23
+
24
+ # ๋‚˜๋ˆ”๊ณ ๋”• ํฐํŠธ ๊ฒฝ๋กœ ์„ค์ • ๋ฐ ๊ฐ•์ œ ์ ์šฉ
25
+ font_path = '/usr/share/fonts/truetype/nanum/NanumGothic.ttf'
26
+
27
+ if os.path.exists(font_path):
28
+ fm.fontManager.addfont(font_path)
29
+ else:
30
+ print("ํฐํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
31
+
32
+ # ๋‚˜๋ˆ”๊ณ ๋”• ํฐํŠธ ๊ฐ•์ œ ์ ์šฉ
33
+ font_prop = fm.FontProperties(fname=font_path)
34
+ plt.rcParams['font.family'] = font_prop.get_name()
35
+ plt.rcParams['axes.unicode_minus'] = False # ๋งˆ์ด๋„ˆ์Šค ๋ถ€ํ˜ธ ๊นจ์ง ๋ฐฉ์ง€
36
+
37
+ # 2. yfinance๋กœ ์ฃผ๊ฐ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ (์‚ผ์„ฑ์ „์ž ์˜ˆ์‹œ)
38
+ ticker = '005930.KS' # ์‚ผ์„ฑ์ „์ž ํ‹ฐ์ปค
39
+ stock = yf.Ticker(ticker)
40
+ stock_data = stock.history(period="max")
41
+
42
+ # ์ฃผ๊ฐ€ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ ํ™•์ธ
43
+ print(stock_data.head()) # ์ฃผ๊ฐ€ ๋ฐ์ดํ„ฐ ์ผ๋ถ€ ํ™•์ธ
44
+
45
+ # 3. ์ฃผ๊ฐ€ ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” (pandas ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์„ numpy ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ฒ˜๋ฆฌ)
46
+ plt.figure(figsize=(10, 6))
47
+
48
+ # ์ธ๋ฑ์Šค์™€ ์ข…๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ numpy ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜
49
+ dates = stock_data.index.to_numpy()
50
+ closing_prices = stock_data['Close'].to_numpy()
51
+
52
+ # ์ฃผ๊ฐ€ ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”
53
+ plt.plot(dates, closing_prices, label='์‚ผ์„ฑ์ „์ž ์ข…๊ฐ€')
54
+
55
+ # ๊ทธ๋ž˜ํ”„ ์ œ๋ชฉ, ์ถ• ๋ผ๋ฒจ์„ ํ•œ๊ธ€๋กœ ์„ค์ •
56
+ plt.title('์‚ผ์„ฑ์ „์ž ์ฃผ๊ฐ€ ์ถ”์ด', fontproperties=font_prop)
57
+ plt.xlabel('๋‚ ์งœ', fontproperties=font_prop)
58
+ plt.ylabel('์ข…๊ฐ€', fontproperties=font_prop)
59
+ plt.legend(prop=font_prop)
60
+
61
+ # B ์ฝ”๋“œ
62
+
63
  # ์ดํ›„ ์ฝ”๋“œ ์‹คํ–‰
64
  import requests
65
  import gradio as gr
 
69
  from PIL import Image
70
  from datetime import datetime, timedelta
71
  from openai import OpenAI
 
72
 
73
  # Perplexity AI API ์„ค์ •
74
+ API_KEY = "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" # ์—ฌ๊ธฐ์— Perplexity AI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
75
 
76
  def get_real_news_summary(company, date):
77
  # OpenAI ํด๋ผ์ด์–ธํŠธ ์ดˆ๊ธฐํ™”
 
209
  )
210
 
211
  # Gradio ์‹คํ–‰
212
+ demo.launch()