Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +57 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
# openai.api_key = os.environ.get('openai.api_key')
|
| 6 |
+
# openai.api_key ="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"
|
| 7 |
+
#页面设置
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="AI绘画(输入文本描述可生成对应图)",
|
| 10 |
+
page_icon=":robot:"
|
| 11 |
+
)
|
| 12 |
+
st.header("🔥AI绘画(输入文本描述可生成对应图)")
|
| 13 |
+
|
| 14 |
+
#检查账号登陆
|
| 15 |
+
def get_text1():
|
| 16 |
+
if 'openai_key' not in st.session_state:
|
| 17 |
+
input_text1 = st.text_input("📫请输入你的账号: ", key="input")
|
| 18 |
+
if st.button("确认登陆!", key="input3"):
|
| 19 |
+
st.session_state['openai_key'] = input_text1
|
| 20 |
+
return input_text1
|
| 21 |
+
else:
|
| 22 |
+
return st.session_state['openai_key']
|
| 23 |
+
|
| 24 |
+
openai_key = get_text1()
|
| 25 |
+
if openai_key:
|
| 26 |
+
openai.api_key = openai_key
|
| 27 |
+
st.write("")
|
| 28 |
+
prompt = st.text_input("📝描述你想画的图")
|
| 29 |
+
|
| 30 |
+
def image(prompt):
|
| 31 |
+
try:
|
| 32 |
+
images = openai.Image.create(
|
| 33 |
+
prompt=prompt,
|
| 34 |
+
n=4,
|
| 35 |
+
size="1024x1024"
|
| 36 |
+
)
|
| 37 |
+
st.empty()
|
| 38 |
+
for image in images["data"]:
|
| 39 |
+
st.image(image["url"],width=300)
|
| 40 |
+
return
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.write("❌❌❌你的账号填写有误,请刷新页面重新填写正确的账号!")
|
| 43 |
+
if st.button("开始绘画"):
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
image(prompt)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
st.write("""
|
| 52 |
+
### 文本生成图技巧:
|
| 53 |
+
|
| 54 |
+
👀描述词格式:主体(描述的是什么)+环境(在什么样的环境下)+风格(图片的风格是什么:二次元、古风、钢笔画等等)
|
| 55 |
+
|
| 56 |
+
✏️描述词例子:上海外滩,白色背景,线稿,钢笔画,速写,4K,未来主义
|
| 57 |
+
""")
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
openai
|