Download frontend/test2.py from rssaem/project1: direct link, hf CLI and curl.
- Browser
- Download file 829 Bytes
-
https://huggingface.co/spaces/rssaem/project1/resolve/main/frontend/test2.py
- Command line
-
hf download hf://spaces/rssaem/project1/frontend/test2.py
-
curl -L -o test2.py https://huggingface.co/spaces/rssaem/project1/resolve/main/frontend/test2.py
829 Bytes
| import streamlit as st | |
| import requests | |
| st.title("Streamlit ๋ฐฑ์๋ ํต์ ์์ (GET)") | |
| # ๋ฐฑ์๋ API URL | |
| #API_URL = "http://localhost:8000/api/data" | |
| API_URL = "https://jsonplaceholder.typicode.com/posts" | |
| if st.button("๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ"): | |
| try: | |
| # ๋ฐฑ์๋์ GET ์์ฒญ ๋ณด๋ | |
| response = requests.get(API_URL) | |
| if response.status_code == 200: | |
| data = response.json() | |
| st.success("๋ฐ์ดํฐ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ฐ์ ธ์์ต๋๋ค!") | |
| st.json(data) # Notion์ด๋ ํ๋ฉด์ ๊น๋ํ๊ฒ JSON ์ถ๋ ฅ | |
| else: | |
| st.error(f"์ค๋ฅ ๋ฐ์: {response.status_code}") | |
| except requests.exceptions.ConnectionError: | |
| st.error("๋ฐฑ์๋ ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์๋ฒ๊ฐ ์ผ์ ธ ์๋์ง ํ์ธํ์ธ์.") |