Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
cd4994b
1
Parent(s):
7339744
Update app.py
Browse files
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()
|