seawolf2357 commited on
Commit
cd4994b
โ€ข
1 Parent(s): 7339744

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -5,8 +5,6 @@ import os
5
  import sys
6
  import json
7
 
8
- # ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ OPENAI API ํ‚ค ๋กœ๋“œ
9
- OPENAI_API_KEY = "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"
10
 
11
  def exception_handler(exception_type, exception, traceback):
12
  print(f"{exception_type.__name__}: {exception}")
@@ -14,7 +12,6 @@ def exception_handler(exception_type, exception, traceback):
14
  sys.excepthook = exception_handler
15
  sys.tracebacklimit = 0
16
 
17
-
18
  def get_chinese_hour(birth_hour):
19
  hour = int(birth_hour[:2])
20
  chinese_hours = ['์ž', '์ถ•', '์ธ', '๋ฌ˜', '์ง„', '์‚ฌ', '์˜ค', '๋ฏธ', '์‹ ', '์œ ', '์ˆ ', 'ํ•ด']
@@ -128,7 +125,6 @@ def get_lunar_info(solYear, solMonth, solDay, solHour):
128
  else:
129
  return {"Error": "API ํ˜ธ์ถœ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."}, "์ •๋ณด ์—†์Œ", "<p>API ํ˜ธ์ถœ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.</p>"
130
 
131
- # ์„ฑ๊ฒฉ๊ณผ ํŠน์ง•์„ ๋ถ„์„ํ•˜๋Š” ํ•จ์ˆ˜ ์ˆ˜์ • (API ํ‚ค ์ธ์ž ์ถ”๊ฐ€)
132
  def analyze_character(lunIljin, OPENAI_API_KEY):
133
  API_URL = "https://api.openai.com/v1/chat/completions"
134
  payload = {
@@ -152,6 +148,7 @@ def analyze_character(lunIljin, OPENAI_API_KEY):
152
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ƒํƒœ ์ฝ”๋“œ: {response.status_code}"
153
 
154
 
 
155
  # ์‚ฌ์ฃผ ๋ถ„์„ ๋ฐ์ดํ„ฐ ์˜ˆ์‹œ (๊ฐ„์†Œํ™”๋œ ๋ฒ„์ „)
156
  ์‚ฌ์ฃผ_๋ฐ์ดํ„ฐ = {
157
  '๊ฐ‘์ž(็”ฒๅญ)' : '์ƒˆ๋กœ์šด ์‹œ์ž‘์˜ ์ƒ์ง•, ๋ฆฌ๋”์‹ญ๊ณผ ๋…๋ฆฝ์„ฑ์ด ํŠน์ง•์ด๋ฉฐ, ํ˜ธ์พŒํ•˜๊ณ  ์„ฑ์‹คํ•œ ํŠน์„ฑ์„ ์ง€๋‹Œ๋‹ค. ',
@@ -228,7 +225,8 @@ def ์‚ฌ์ฃผ_๋ถ„์„(๋…„์ฃผ, ์›”์ฃผ, ์ผ์ฃผ, ์‹œ์ฃผ):
228
  </div>
229
  """
230
  return html_result
231
-
 
232
  with gr.Blocks() as demo:
233
  with gr.Tab("AI ์‚ฌ์ฃผ ์šด์„ธ ๋ถ„์„"):
234
  solYear = gr.Textbox(label="์ƒ๋…„(์˜ˆ: 1990)")
@@ -236,12 +234,10 @@ with gr.Blocks() as demo:
236
  solDay = gr.Textbox(label="์ƒ์ผ(์˜ˆ: 31)")
237
  solHour = gr.Textbox(label="์ƒ์‹œ(์˜ˆ์‹œ: 1030)", placeholder="์‹œ๊ฐ„์„ 24์‹œ๊ฐ„ ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•˜์„ธ์š” (์˜ˆ: 2230)")
238
  output1 = gr.JSON(label="๊ฒฐ๊ณผ")
239
- analysis_result = gr.HTML() # ์‚ฌ์ฃผ ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•  HTML ์ปดํฌ๋„ŒํŠธ ๋จผ์ € ์„ ์–ธ
240
- # ์ผ์ฃผ๋ฅผ ์ €์žฅํ•  State ์ถ”๊ฐ€
241
- lunIljin_state = gr.State()
242
  get_lunar_info_btn = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
243
 
244
- # ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •, outputs ์ˆœ์„œ์— ๋งž๊ฒŒ ์ˆ˜์ •
245
  get_lunar_info_btn.click(
246
  fn=get_lunar_info,
247
  inputs=[solYear, solMonth, solDay, solHour],
@@ -252,7 +248,6 @@ with gr.Blocks() as demo:
252
  OPENAI_API_KEY_input = gr.Textbox(label="OpenAI API ํ‚ค", placeholder="์—ฌ๊ธฐ์— OpenAI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")
253
  character_output = gr.Textbox(label="์„ฑ๊ฒฉ๊ณผ ํŠน์ง•")
254
  analyze_button = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
255
- # analyze_character ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ lunIljin_state์™€ OPENAI_API_KEY_input๋ฅผ ์ž…๋ ฅ์œผ๋กœ ์‚ฌ์šฉ
256
  analyze_button.click(fn=analyze_character, inputs=[lunIljin_state, OPENAI_API_KEY_input], outputs=character_output)
257
 
258
- demo.launch()
 
5
  import sys
6
  import json
7
 
 
 
8
 
9
  def exception_handler(exception_type, exception, traceback):
10
  print(f"{exception_type.__name__}: {exception}")
 
12
  sys.excepthook = exception_handler
13
  sys.tracebacklimit = 0
14
 
 
15
  def get_chinese_hour(birth_hour):
16
  hour = int(birth_hour[:2])
17
  chinese_hours = ['์ž', '์ถ•', '์ธ', '๋ฌ˜', '์ง„', '์‚ฌ', '์˜ค', '๋ฏธ', '์‹ ', '์œ ', '์ˆ ', 'ํ•ด']
 
125
  else:
126
  return {"Error": "API ํ˜ธ์ถœ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."}, "์ •๋ณด ์—†์Œ", "<p>API ํ˜ธ์ถœ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.</p>"
127
 
 
128
  def analyze_character(lunIljin, OPENAI_API_KEY):
129
  API_URL = "https://api.openai.com/v1/chat/completions"
130
  payload = {
 
148
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ƒํƒœ ์ฝ”๋“œ: {response.status_code}"
149
 
150
 
151
+
152
  # ์‚ฌ์ฃผ ๋ถ„์„ ๋ฐ์ดํ„ฐ ์˜ˆ์‹œ (๊ฐ„์†Œํ™”๋œ ๋ฒ„์ „)
153
  ์‚ฌ์ฃผ_๋ฐ์ดํ„ฐ = {
154
  '๊ฐ‘์ž(็”ฒๅญ)' : '์ƒˆ๋กœ์šด ์‹œ์ž‘์˜ ์ƒ์ง•, ๋ฆฌ๋”์‹ญ๊ณผ ๋…๋ฆฝ์„ฑ์ด ํŠน์ง•์ด๋ฉฐ, ํ˜ธ์พŒํ•˜๊ณ  ์„ฑ์‹คํ•œ ํŠน์„ฑ์„ ์ง€๋‹Œ๋‹ค. ',
 
225
  </div>
226
  """
227
  return html_result
228
+
229
+
230
  with gr.Blocks() as demo:
231
  with gr.Tab("AI ์‚ฌ์ฃผ ์šด์„ธ ๋ถ„์„"):
232
  solYear = gr.Textbox(label="์ƒ๋…„(์˜ˆ: 1990)")
 
234
  solDay = gr.Textbox(label="์ƒ์ผ(์˜ˆ: 31)")
235
  solHour = gr.Textbox(label="์ƒ์‹œ(์˜ˆ์‹œ: 1030)", placeholder="์‹œ๊ฐ„์„ 24์‹œ๊ฐ„ ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•˜์„ธ์š” (์˜ˆ: 2230)")
236
  output1 = gr.JSON(label="๊ฒฐ๊ณผ")
237
+ analysis_result = gr.HTML() # ์‚ฌ์ฃผ ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•  HTML ์ปดํฌ๋„ŒํŠธ
238
+ lunIljin_state = gr.State() # ์ผ์ฃผ๋ฅผ ์ €์žฅํ•  State
 
239
  get_lunar_info_btn = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
240
 
 
241
  get_lunar_info_btn.click(
242
  fn=get_lunar_info,
243
  inputs=[solYear, solMonth, solDay, solHour],
 
248
  OPENAI_API_KEY_input = gr.Textbox(label="OpenAI API ํ‚ค", placeholder="์—ฌ๊ธฐ์— OpenAI API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")
249
  character_output = gr.Textbox(label="์„ฑ๊ฒฉ๊ณผ ํŠน์ง•")
250
  analyze_button = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
 
251
  analyze_button.click(fn=analyze_character, inputs=[lunIljin_state, OPENAI_API_KEY_input], outputs=character_output)
252
 
253
+ demo.launch()