Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# API 호출 함수 정의
|
| 5 |
+
def search_postal_code(region, city, town):
|
| 6 |
+
base_url = "https://api.odcloud.kr/api/15070405/v1/uddi:dd22ecb1-d970-4d91-af69-97155311dc0a"
|
| 7 |
+
api_key = "YOUR_API_KEY_HERE" # 실제 API 키로 대체해야 함
|
| 8 |
+
params = {
|
| 9 |
+
"serviceKey": api_key,
|
| 10 |
+
"perPage": "10", # 한 번에 받아올 데이터 수
|
| 11 |
+
"page": "1", # 페이지 번호
|
| 12 |
+
# 추가적인 필터링이 필요하다면 여기에 파라미터 추가
|
| 13 |
+
}
|
| 14 |
+
response = requests.get(base_url, params=params)
|
| 15 |
+
if response.status_code == 200:
|
| 16 |
+
data = response.json()
|
| 17 |
+
# API 응답에서 우편번호 데이터 추출 로직 구현 필요
|
| 18 |
+
return data
|
| 19 |
+
else:
|
| 20 |
+
return "API 호출 실패: " + str(response.status_code)
|
| 21 |
+
|
| 22 |
+
# Gradio 인터페이스 정의
|
| 23 |
+
interface = gr.Interface(
|
| 24 |
+
fn=search_postal_code,
|
| 25 |
+
inputs=[gr.Textbox(label="도이름"), gr.Textbox(label="시군구이름"), gr.Textbox(label="읍면동이름")],
|
| 26 |
+
outputs="json",
|
| 27 |
+
title="우편번호 검색 프로그램",
|
| 28 |
+
description="도이름, 시군구이름, 읍면동이름을 입력하면 해당 지역의 우편번호를 검색해줍니다."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# 애플리케이션 실행
|
| 32 |
+
interface.launch()
|