File size: 1,657 Bytes
21048e8
145ad7d
21048e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# gradio 라이브러리λ₯Ό gr λ³„μΉ­μœΌλ‘œ μž„ν¬νŠΈν•©λ‹ˆλ‹€.
import gradio as gr
from gradio_client import Client
import httpx

# Client 객체 생성 μ‹œ timeout λ§€κ°œλ³€μˆ˜ 제거
client = Client("seawolf2357/sajuice")




# νƒ€μž„μ•„μ›ƒ 값을 초 λ‹¨μœ„λ‘œ μ„€μ •ν•©λ‹ˆλ‹€. 예: 읽기 νƒ€μž„μ•„μ›ƒμ„ 30초둜 μ„€μ •
timeout_config = httpx.Timeout(5.0, read=30.0)

try:
    # μˆ˜μ •λœ νƒ€μž„μ•„μ›ƒ 섀정을 μ μš©ν•˜μ—¬ ν΄λΌμ΄μ–ΈνŠΈλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
    client = Client("arxivgpt/sajutest", timeout=timeout_config)
    print("ν΄λΌμ΄μ–ΈνŠΈκ°€ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
except httpx.ReadTimeout:
    print("μš”μ²­ μ‹œκ°„ 초과: μ„œλ²„κ°€ μ§€μ •λœ μ‹œκ°„ 내에 μ‘λ‹΅ν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.")
except Exception as e:
    print(f"μ˜ˆμƒμΉ˜ λͺ»ν•œ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")


def call_api(생년, 생월, 생일, μƒμ‹œ):
    # APIλ₯Ό ν˜ΈμΆœν•˜κ³  응닡값을 λ°›μŠ΅λ‹ˆλ‹€.
    result = client.predict(
        생년,    # '생년(예: 1990)'에 λŒ€ν•œ μž…λ ₯κ°’
        생월,    # '생월(예: 01)'에 λŒ€ν•œ μž…λ ₯κ°’
        생일,    # '생일(예: 31)'에 λŒ€ν•œ μž…λ ₯κ°’
        μƒμ‹œ,    # 'μƒμ‹œ(μ˜ˆμ‹œ: 1030)'에 λŒ€ν•œ μž…λ ₯κ°’
        api_name="/get_lunar_info"
    )
    return result

# Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.
inputs = [
    gr.Textbox(label="생년(예: 1990)"),
    gr.Textbox(label="생월(예: 01)"),
    gr.Textbox(label="생일(예: 31)"),
    gr.Textbox(label="μƒμ‹œ(μ˜ˆμ‹œ: 1030)")
]
outputs = gr.Textbox(label="κ²°κ³Ό")

# μΈν„°νŽ˜μ΄μŠ€λ₯Ό μƒμ„±ν•˜κ³  μ‹€ν–‰ν•©λ‹ˆλ‹€.
gr.Interface(fn=call_api, inputs=inputs, outputs=outputs, title="Get Lunar Info").launch()