
목차
🚨 문제 상황
🔍 문제 원인 분석
⚡ 두 방법의 원리
💡 최종 해결 방법
Google Colab에서 Streamlit 앱 테스트를 위한 실행시 에러 발생
Colab은 자체적으로 외부 포트를 직접 열 수 없기 때문에, colab에서 streamlit 실행을 하려면 터널링 툴을 이용해야 합니다.
터널링은 로컬(Colab 내부)에서 실행 중인 웹 서버를 공용 인터넷에서 접근 가능한 URL로 연결해 주는 방식입니다.
따로 계정 발급이 필요 없는 아래 두 가지 무료 방식을 시도해 보았습니다.
⚙️ 시도 과정
시도 1: localtunnel 사용
참고 : https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399
# app.py로 실행하려는 파일 저장 후 아래 코드 실행
!npm install -g localtunnel
!streamlit run app.py &>/content/logs.txt &
import urllib
print("Password/Enpoint IP for localtunnel is:",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip("\n"))
# 위 코드 실행하여 나온 IP 주소를 아래 코드 실행 후 나온 링크에 접속하여 입력
!lt --port 8501 --subdomain youtube-blog-1234 &
시도 2: cloudflared 사용
!wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -O cloudflared.deb
!dpkg -i cloudflared.deb || apt-get -f install -y
!streamlit run app.py --server.address 0.0.0.0 --server.port 8501 &>/content/streamlit.log &
!cloudflared tunnel --url http://localhost:8501 --no-autoupdate > cf.log 2>&1 &