Commit
b25c845
ยท
verified ยท
1 Parent(s): 34db63a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -27
app.py CHANGED
@@ -1,37 +1,38 @@
1
  import subprocess
2
  import sys
3
-
4
- # ํŒจํ‚ค์ง€ ์„ค์น˜ (ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ ๋ฐ ์—…๋ฐ์ดํŠธ)
5
- def install_packages():
6
- subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"])
7
- subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "openai", "yfinance", "gradio", "matplotlib", "Pillow"])
8
- subprocess.check_call(["apt-get", "install", "-y", "fonts-nanum"])
9
- subprocess.check_call(["fc-cache", "-fv"])
10
-
11
- # ํŒจํ‚ค์ง€ ์„ค์น˜
12
- install_packages()
13
-
14
- # ์„ค์น˜ ํ›„ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€ ์ž„ํฌํŠธ
15
  import os
16
  import matplotlib.font_manager as fm
17
  import matplotlib.pyplot as plt
18
  import io
19
  from PIL import Image
20
- import yfinance as yf
21
- import gradio as gr
22
  from datetime import datetime
 
 
23
  from openai import OpenAI
 
24
 
25
- # ๋‚˜๋ˆ”๊ณ ๋”• ํฐํŠธ ๊ฒฝ๋กœ ์„ค์ • ๋ฐ ๊ฐ•์ œ ์ ์šฉ
26
- font_path = '/usr/share/fonts/truetype/nanum/NanumGothic.ttf'
 
 
27
 
28
- if os.path.exists(font_path):
 
 
 
 
 
 
 
 
 
29
  fm.fontManager.addfont(font_path)
30
  font_prop = fm.FontProperties(fname=font_path)
31
  plt.rcParams['font.family'] = font_prop.get_name()
32
  plt.rcParams['axes.unicode_minus'] = False # ๋งˆ์ด๋„ˆ์Šค ๋ถ€ํ˜ธ ๊นจ์ง ๋ฐฉ์ง€
33
- else:
34
- print("ํฐํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
 
35
 
36
  # Perplexity AI API ์„ค์ •
37
  API_KEY = "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" # ์—ฌ๊ธฐ์— Perplexity AI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
@@ -141,13 +142,12 @@ with gr.Blocks() as demo:
141
 
142
  submit_btn = gr.Button("Submit")
143
 
144
- # ์˜ˆ์ œ (์ด์ „ ๋ ˆ์ด์•„์›ƒ์œผ๋กœ ๋ณต์›)
145
  examples = [["SK๋ฐ”์ด์˜คํŒœ"],
146
- ["๋‚˜์Šค๋‹ฅ ์‹œ์ด 1์œ„"],
147
- ["๋‚˜์Šค๋‹ฅ ์ œ์•ฝ์ฃผ ์‹œ์ด 1์œ„"],
148
- ["๋‚˜์Šค๋‹ฅ ๋ฐ”์ด์˜คํ… ์‹œ์ด 1์œ„"],
149
- ["์ฝ”์Šคํ”ผ ์‹œ์ด 1์œ„"],
150
- ["์ฝ”์Šค๋‹ฅ ์‹œ์ด 1์œ„"]]
151
  gr.Examples(examples=examples, inputs=[input_value])
152
 
153
  with gr.Column(): # ๊ทธ๋ž˜ํ”„๋ฅผ ์ถœ๋ ฅํ•  ๋‘ ๋ฒˆ์งธ ์—ด
@@ -173,5 +173,3 @@ with gr.Blocks() as demo:
173
 
174
  # Gradio ์‹คํ–‰
175
  demo.launch()
176
-
177
-
 
1
  import subprocess
2
  import sys
 
 
 
 
 
 
 
 
 
 
 
 
3
  import os
4
  import matplotlib.font_manager as fm
5
  import matplotlib.pyplot as plt
6
  import io
7
  from PIL import Image
 
 
8
  from datetime import datetime
9
+ import gradio as gr
10
+ import yfinance as yf
11
  from openai import OpenAI
12
+ import requests
13
 
14
+ # ํŒจํ‚ค์ง€ ์„ค์น˜ (ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ ๋ฐ ์—…๋ฐ์ดํŠธ)
15
+ def install_packages():
16
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"])
17
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "openai", "yfinance", "gradio", "matplotlib", "Pillow"])
18
 
19
+ # ํŒจํ‚ค์ง€ ์„ค์น˜
20
+ install_packages()
21
+
22
+ # ๋‚˜๋ˆ”๊ณ ๋”• ํฐํŠธ ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์ •
23
+ def download_and_setup_font():
24
+ font_url = 'https://github.com/naver/nanumfont/blob/master/ttf/NanumGothic.ttf?raw=true'
25
+ font_path = os.path.join(os.path.expanduser("~"), 'NanumGothic.ttf')
26
+ response = requests.get(font_url)
27
+ with open(font_path, 'wb') as f:
28
+ f.write(response.content)
29
  fm.fontManager.addfont(font_path)
30
  font_prop = fm.FontProperties(fname=font_path)
31
  plt.rcParams['font.family'] = font_prop.get_name()
32
  plt.rcParams['axes.unicode_minus'] = False # ๋งˆ์ด๋„ˆ์Šค ๋ถ€ํ˜ธ ๊นจ์ง ๋ฐฉ์ง€
33
+
34
+ # ํฐํŠธ ์„ค์ •
35
+ download_and_setup_font()
36
 
37
  # Perplexity AI API ์„ค์ •
38
  API_KEY = "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" # ์—ฌ๊ธฐ์— Perplexity AI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
 
142
 
143
  submit_btn = gr.Button("Submit")
144
 
145
+ # ์˜ˆ์ œ
146
  examples = [["SK๋ฐ”์ด์˜คํŒœ"],
147
+ ["Apple"],
148
+ ["์‚ผ์„ฑ์ „์ž"],
149
+ ["005930.KS"],
150
+ ["AAPL"]]
 
151
  gr.Examples(examples=examples, inputs=[input_value])
152
 
153
  with gr.Column(): # ๊ทธ๋ž˜ํ”„๋ฅผ ์ถœ๋ ฅํ•  ๋‘ ๋ฒˆ์งธ ์—ด
 
173
 
174
  # Gradio ์‹คํ–‰
175
  demo.launch()