Summary
I’m using streamlit to provide an easy Web UI interface to interact with python scripts. I am really playing around. The snippet below is from a code where I calc a Bhaskara’s formula.
It runs smoothly on python3 command line on my Ubuntu virtual machine, but when I try to run it with Streamlit, it hangs for around 8 minutes.
If run the entire code, it hangs forever (13+ hours).
What am I doing wrong?
Steps to reproduce
- run “streamlit run while.py” on Linux terminal
- enter value for etiqueta, like 16 and ensures data was input - no red line surrounding the input field
3)8+ minutes, the result is shown 4.0
Code snippet:
#! /usr/bin/python3
import streamlit as st
deupau = False
i = 0
calculodelta = st.number_input(label="etiqueta")
while deupau == False:
i += 1
divisao = calculodelta / i
if divisao == i:
i2 = divisao
deupau = True
else:
deupau = False
st.write(i2)
Debug info
-
Streamlit version: 1.13.0
-
Python version: 3.10.6
-
Using Conda? Not sure, but I’ve installed pipenv following this reference:
https://docs.streamlit.io/library/get-started/installation#install-streamlit-on-macoslinux -
OS version: Ubuntu 22.04.1 64bit
-
Browser version: Chrome 106.0.5249.79 Android, but also on latest Chrome on Windows 10 desktop
Full code snippet for reference
…
#! /usr/bin/python3
import streamlit as st
st.title (“Formula de Bhaskara”)
def run():
st.set_page_config(
page_title=“Formula de Bhaskara”,
page_icon=“”,
)
st.write(“”)
i = 0
deupau = False
st.write(“Formula de Bhaskara”)
st.write(“”)
st.write(“X1=-B+Raiz(Delta)”)
st.write(“--------------------”)
st.write(“2A”)
st.write(“”)
st.write(“X2=-B-Raiz(Delta)”)
st.write(“----------------------------”)
st.write(“2A”)
st.write(“”)
#Imagem01
st.image()
st.write (“Calcula a Bhaska ai pra Noiz!”)
#USER st.number_input
st.write(“Qual é o valor de A?”)
a = st.number_input(“Sugestão 1: " )
st.write(”")
st.write("Valor de A: ", a)
st.write("Qual é o valor de B? “)
b = st.number_input(“Sugestão 8: " )
st.write(””)
st.write("Valor de B ", b)
st.write(“Qual é o valor de C?”)
c = st.number_input(“Sugestão -9: " )
st.write(”“)
st.write(“Valor de C “, c)
#calculodelta
#Imagem 02
st.image(””)
st.write(”“)
st.write(“Calculo do Delta”)
calculodelta = (b * b) - (4 * a * c)
st.write(“Valores previos”)
st.write(“A = “, a)
st.write(“B = “, b)
st.write(“C = “, c)
st.write(””)
st.write(“Delta = B2 - 4AC”)
st.write(“Delta = “,”(”,b,”“,b,”) - (4”,a,”*”,c,”)")
st.write("Delta = ", calculodelta)
#(calculo raiz)
st.write(“”)
st.image(“”)
st.write(“”)
st.write(“Calculo da Raiz”)
#While resultado for diferente de deltaraiz
st.write(“”)
st.write(“Inicio do loop Calculo RAIZ”)
st.write(“Valor Delta:”, calculodelta)
st.write(“Valor I inicial:”, i)
while deupau == False:
i += 1
divisao = calculodelta / i
resultado = divisao * i
if divisao == i:
i2 = divisao
deupau = True
else:
deupau = False
st.write(“”)
st.write(“Valor de I atualizado: “,i)
st.write(“Raiz de Delta: “,i2)
st.write(””)
#imagem 04
st.image(””)
st.write(“”)
st.write(“Calculo X1 e X2”)
st.write(“X1”)
st.write(“X1 = - B + Raiz(Delta)”)
st.write(“----------------------------”)
st.write(“2 * A”)
st.write(“”)
st.write(“X1 = -”,b,’ + ‘,i2)
st.write(“----------------------------”)
st.write(“2 * “, a)
st.write(””)
x1=-(b+i2)/2a
x2=-(b-i2)/2a
st.write(“X1 = “, x2)
st.write(””)
st.write(“X2”)
st.write(“X2 = - B - Raiz(Delta)”)
st.write(“----------------------------”)
st.write(“2 * A”)
st.write(“”)
st.write(“X2 = -”,b,’ - ',i2)
st.write(“----------------------------”)
st.write(“2 * “, a)
st.write(””)
st.write(“X2 = “, x1)
st.write(””)
#por algum problema de sintaxe python ou logica matematica
#o calculo esta invertendo sinal positivo com negativo
#entao para nao perder mais tempo, inverti as variaveis
#de resultado na impressao do console
st.write(“Olha o veio Baka ae, quer dizer, Bhaskara”)
st.image(“”)
st.write(“”)
st.write(“MAS…”)
st.video(“”)
st.write(“Site de referência”)
st.write(“Fórmula de Bhaskara - Mundo Educação”)
st.write(“Obrigado!! Mafia Dac”)
st.write(“”)
…