Search code examples
pythonmachine-learningngrokstreamlitpyngrok

url generated for Streamlit not working properly. ngrok tells me to register again even though I have already registered or gives me an error


Below is my code for deploying my ml model on streamlit.

I am using Google Collab

!pip install streamlit --quiet
!pip install pyngrok==4.1.1
from pyngrok import ngrok
%%writefile app.py
import streamlit as st
import joblib
st.title('Spam Ham Deployment')
test_model=joblib.load('spam_ham')
ip=st.text_input('Enter your message')
op=test_model.predict([ip])
if st.button('Predict')
  st.title(op)
!nohup streamlit run app.py &
url=ngrok.connect(port='8501')
url

Note: Initially I did not have ngrok on my PC

After running the last code block I got the url but ngrok wanted me to create an account. I created an account, extracted ngrok on Windows, authenticated my ngrok agent and restarted my computer. I ran the last block again and got an error "Your account may not run more than 2 tunnels over a single ngrok client session." So I killed the process and ran all code blocks. However, after gettiing the URl and running it in the browser it tells to to register again.

Note: There is a warning when the URL is generated 't=2022-01-22T22:40:55+0000 lvl=warn msg="can't bind default web address, trying alternatives" obj=web addr=127.0.0.1:4040'

Why is this hapenning?

Can someone tell me what I should to do in order to solve the situation?

Edit: I tried to change port to 5040 that has listening state but then it shows a different error 'The connection to http://9039-35-186-177-6.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:5040.'


Solution

  • Use heroku or vercel instead of ngrok. ngrok is highly unstable.