最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How do I recall my function img when it is in a if statement and im making an elif statement under it? - Stack Overflow

programmeradmin2浏览0评论

I am trying to make a website that can let you take pictures with your camera and converts that picture into grey and also lets you upload an image that gets converted to grey but the problem is that I want the camera button to disappear as in like it minimizes to a small tab and when you press on it, it will expand back to normal. But when I want to call the img variable to close the camera screen it would give me an error because it can't be identified in the elif statement how would I fix this problem?

My code:

import streamlit as st
from PIL import Image

uploaded_image = st.file_uploader("Upload Image")

camera_image = st.camera_input('Camera')

if camera_image:
    img = Image.open(camera_image)

    gray_img = img.convert("L")

    st.image(gray_img)

elif uploaded_image:
    uploaded_image = Image.open(uploaded_image)

    gray_img = uploaded_image.convert("L")

    st.image(gray_img)

    img.close

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论