【问题标题】:user input is not capturing the text用户输入未捕获文本
【发布时间】:2022-08-15 02:54:32
【问题描述】:

每当我单击按钮而不是显示框自动关闭的文本时,我都试图使用带有“电子邮件”按钮的文本输入来捕获文本

我已经尝试过,但不知道问题出在哪里,任何想法都将不胜感激

import streamlit as st #web app and camera
import numpy as np # for image processing 
from PIL import Image #Image processing 
import cv2 #computer vision 

def dodgeV2(x, y):
    return cv2.divide(x, 255 - y, scale=256)

def pencilsketch(inp_img):
    img_gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
    img_invert = cv2.bitwise_not(img_gray)
    img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)
    final_img = dodgeV2(img_gray, img_smoothing)
    return(final_img)


file_image = st.camera_input(label = \"Take a pic of you to be sketched out\")

if file_image:
    input_img = Image.open(file_image)
    final_sketch = pencilsketch(np.array(input_img))
    st.write(\"**Output Pencil Sketch**\")
    st.image(final_sketch, use_column_width=True)
    if st.button(\"Download Sketch Images\"):
        im_pil = Image.fromarray(final_sketch)
        im_pil.save(\'final_image.jpeg\')
        st.write(\'Download completed\')
#the issue code starts from here
        if st.button(\"Email\"):
            form = st.form(key=\'my-form\')
            name = form.text_input(\'Enter your name\')
            submit = form.form_submit_button(\'Submit\')
            st.write(\'Press submit to have your name printed below\')
            if submit:
                st.write(f\'hello {name}\')
                
    
    else:
         st.write(\"You haven\'t uploaded any image file\")

    标签: python streamlit


    【解决方案1】:

    如果您在按钮下尝试其他用户交互,则 Streamlit 按钮会话操作仅一次,页面将重新加载,因此您会丢失数据,但您可以使用复选框 st.checkbox 解决它

     if st.checkbox("Send Email"): # Modified
        form = st.form(key='my-form')
        name = form.text_input('Enter your name')
        submit_button = form.form_submit_button(label='Submit') # Modified
        st.write('Press submit to have your name printed below')
        if submit_button: # Modified
            st.write(f'hello {name}')
    

    这应该可以正常工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-01
      • 2023-03-11
      • 1970-01-01
      • 2014-07-07
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多