作者 | 小欣
来源 |Python爱好者集中营
Python
做了一个网页版的“P图软件”,大致的流程在于我们可以将上传的照片进行黑白处理、铅笔素描处理、模糊化处理等一系列操作,具体如下importstreamlitasst
importnumpyasnp
importcv2
fromPILimportImage,ImageEnhance
st.sidebar.markdown('<pclass="font">MyFirstPhotoConverterApp</p>',unsafe_allow_html=True)
withst.sidebar.expander("AbouttheApp"):
st.write("""
Usethissimpleapptoconvertyourfavoritephototoapencilsketch,agrayscaleimageoranimagewithblurringeffect.\n\nThisappwascreatedbyJunxinasasideprojecttolearnStreamlitandcomputervision.Hopeyouenjoy!
""")
streamlit模块当中的sidebar
方法来生成一个下拉框,在通过点击“+”键来打开,
filter=st.sidebar.radio('Covertyourphototo:',['Original','GrayImage','BlackandWhite','PencilSketch','BlurEffect'])
sidebar
方法来实现的,当中添加上分别是哪些的单选项,st.sidebar.title('')
st.sidebar.markdown('')
st.sidebar.subheader('Pleasehelpusimprove!')
withst.sidebar.form(key='columns_in_form',clear_on_submit=True):
rating=st.slider("Pleaseratetheapp",min_value=1,max_value=5,value=3,help='Dragtheslidertoratetheapp.Thisisa1-5ratingscalewhere5isthehighestrating')
text=st.text_input(label='Pleaseleaveyourfeedbackhere')
submitted=st.form_submit_button('Submit')
ifsubmitted:
.......
withcol1:
st.markdown("""<style>.font{
font-size:35px;font-family:'CooperBlack';color:#FF9633;}
</style>""",unsafe_allow_html=True)
st.markdown('<pclass="font">Uploadyourphotohere...</p>',unsafe_allow_html=True)
uploaded_file=st.file_uploader("",type=['jpg','png','jpeg'])
streamlit
模块当中的file_uploader
方法,其中允许上传的有三种文件格式,分别是jpg
、png
以及jpeg
。withcol2:
filter=st.sidebar.radio('Covertyourphototo:',['Original','GrayImage','BlackandWhite','PencilSketch','BlurEffect'])
iffilter=='GrayImage':
converted_img=np.array(image.convert('RGB'))
gray_scale=cv2.cvtColor(converted_img,cv2.COLOR_RGB2GRAY)
......
eliffilter=='BlackandWhite':
......
eliffilter=='PencilSketch':
......
eliffilter=='BlurEffect':
......
else:
st.image(image,width=300)
分享
点收藏
点点赞
点在看
文章转发自AI科技大本营微信公众号,版权归其所有。文章内容不代表本站立场和任何投资暗示。
Copyright © 2021.Company 元宇宙YITB.COM All rights reserved.元宇宙YITB.COM