import streamlit as st import os import openai # openai.api_key = os.environ.get('openai.api_key') # openai.api_key ="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" #页面设置 st.set_page_config( page_title="AI绘画(输入文本描述可生成对应图)", page_icon=":robot:" ) st.header("🔥AI绘画(输入文本描述可生成对应图)") #检查账号登陆 def get_text1(): if 'openai_key' not in st.session_state: input_text1 = st.text_input("📫请输入你的账号: ", key="input") if st.button("确认登陆!", key="input3"): st.session_state['openai_key'] = input_text1 return input_text1 else: return st.session_state['openai_key'] openai_key = get_text1() if openai_key: openai.api_key = openai_key st.write("") prompt = st.text_input("📝描述你想画的图") def image(prompt): try: images = openai.Image.create( prompt=prompt, n=4, size="1024x1024" ) st.empty() for image in images["data"]: st.image(image["url"],width=300) return except Exception as e: st.write("❌❌❌你的账号填写有误,请刷新页面重新填写正确的账号!") if st.button("开始绘画"): image(prompt) st.write(""" ### 文本生成图技巧: 👀描述词格式:主体(描述的是什么)+环境(在什么样的环境下)+风格(图片的风格是什么:二次元、古风、钢笔画等等) ✏️描述词例子:上海外滩,白色背景,线稿,钢笔画,速写,4K,未来主义 """)