Download app.py from honey90/postcode: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/honey90/postcode/resolve/main/app.py
- Command line
-
hf download hf://spaces/honey90/postcode/app.py
-
curl -L -o app.py https://huggingface.co/spaces/honey90/postcode/resolve/main/app.py
1.3 kB
| import gradio as gr | |
| import requests | |
| # API 호출 함수 정의 | |
| def search_postal_code(region, city, town): | |
| base_url = "https://api.odcloud.kr/api/15070405/v1/uddi:dd22ecb1-d970-4d91-af69-97155311dc0a" | |
| api_key = "/15070405/v1/uddi:dd22ecb1-d970-4d91-af69-97155311dc0a" # 실제 API 키로 대체해야 함 | |
| params = { | |
| "serviceKey": api_key, | |
| "perPage": "10", # 한 번에 받아올 데이터 수 | |
| "page": "1", # 페이지 번호 | |
| # 추가적인 필터링이 필요하다면 여기에 파라미터 추가 | |
| } | |
| response = requests.get(base_url, params=params) | |
| if response.status_code == 200: | |
| data = response.json() | |
| # API 응답에서 우편번호 데이터 추출 로직 구현 필요 | |
| return data | |
| else: | |
| return "API 호출 실패: " + str(response.status_code) | |
| # Gradio 인터페이스 정의 | |
| interface = gr.Interface( | |
| fn=search_postal_code, | |
| inputs=[gr.Textbox(label="도이름"), gr.Textbox(label="시군구이름"), gr.Textbox(label="읍면동이름")], | |
| outputs="json", | |
| title="우편번호 검색 프로그램", | |
| description="도이름, 시군구이름, 읍면동이름을 입력하면 해당 지역의 우편번호를 검색해줍니다." | |
| ) | |
| # 애플리케이션 실행 | |
| interface.launch() |