From 5a405a59c075443ad02415a927bcf23036aa6377 Mon Sep 17 00:00:00 2001
From: Muhan Xu <53051442+ryananan@users.noreply.github.com>
Date: Sun, 24 Apr 2022 13:17:12 +0800
Subject: [PATCH 1/6] update prompt engineering text and format
---
ai-atelier-cn.py | 108 ++++++++++++++++++++++++++---------------------
ai-atelier.py | 60 +++++++++++++++-----------
2 files changed, 96 insertions(+), 72 deletions(-)
diff --git a/ai-atelier-cn.py b/ai-atelier-cn.py
index 4c54149..6f1f6c8 100644
--- a/ai-atelier-cn.py
+++ b/ai-atelier-cn.py
@@ -21,10 +21,10 @@
from kora.xattr import get_id
import deepl
-from setup import textsynth_completion
-from setup import deeplSetup
-# from setup_mac import textsynth_completion
-# from setup_mac import deeplSetup
+# from setup import textsynth_completion
+# from setup import deeplSetup
+from setup_mac import textsynth_completion
+from setup_mac import deeplSetup
translator = deeplSetup()
@@ -46,8 +46,8 @@
/*Generate your answers button*/
.appview-container > section > div > div > div > div.css-1p05t8e.epcbefy1 > div:nth-child(1) > div > div > div > div > button{color: #B6A4FC}
-/*history link
-.appview-container > section > div > div > div > div:nth-child(6) > div:nth-child(1) > div > div.css-ocqkz7.e1tzin5v0 > div.css-q8vomm.e1tzin5v2{color: rgb(209 209 209 / 35%); padding:0px; position:relative; top:6px; left:-4px}*/
+/*like button*/
+.appview-container > section > div > div:nth-child(1) > div > div:nth-child(6) > div:nth-child(1) > div > div:nth-child(6){position: relative; right: -134px; top: -51.5px; margin: 0; color: #B6A4FC}
# .css-ffhzg2 div[data-testid="stExpander"]{background-color: rgb(14, 17, 23)}
# .css-fg4pbf div[data-testid="stExpander"]{background-color: white}
@@ -79,6 +79,7 @@
.appview-container > section > div > div > div > div:nth-child(11) .streamlit-expanderContent div[data-testid="stVerticalBlock"] div:nth-child(2) > div {flex-direction: row !important;flex-wrap: wrap}
.appview-container > section > div > div > div > div:nth-child(11) .streamlit-expanderContent div[data-testid="stVerticalBlock"] div:nth-child(2) > div div{width: auto !important}
+
/*Horizontal Radio - Image generation model*/
div.row-widget.stRadio > div{flex-direction:row} div.row-widget.stRadio > div label {margin-right: .75em;} div.row-widget.stRadio > div label:last-child{margin-right: 0}
@@ -138,6 +139,7 @@ class DefaultPaths:
)
st.subheader('💬 问问AI [文本生成文本]')
+
def add_heart_item():
if DefaultPaths.is_drive:
text_output_folder = f"{DefaultPaths.drive_path}/text_history"
@@ -153,7 +155,7 @@ def add_heart_item():
def open_history_log():
from kora.xattr import get_id
-
+
if DefaultPaths.is_drive:
output_folder = f"{DefaultPaths.drive_path}/text_history"
if not path_exists(output_folder):
@@ -208,7 +210,8 @@ def text_main():
with st.form(key="text_generation"):
submit_button = st.form_submit_button(label="看看AI的回答")
if submit_button:
- user_input = str(translator.translate_text(user_input_ch, target_lang="EN-GB"))
+ user_input = str(translator.translate_text(
+ user_input_ch, target_lang="EN-GB"))
demonstrations = '''
Q: Describe the most beautiful alien life in your mind
A: The most beautiful alien life in my mind is a gentle and peaceful race of creatures that live in the stars. They are incredibly graceful, and their beauty is breathtaking. They are always happy and enjoy spending time with others of their kind. They are the perfect representation of peace and harmony in the universe.
@@ -233,7 +236,8 @@ def text_main():
st.write("🙂 Q: " + user_input + ' \n🤖 A: ' + res)
answer_result_ch = str(translator.translate_text(res, target_lang="ZH"))
- st.write("🙂 Q: " + user_input_ch + ' \n🤖 A: ' + answer_result_ch)
+ st.write("🙂 Q: " + user_input_ch +
+ ' \n🤖 A: ' + answer_result_ch)
if DefaultPaths.is_drive:
text_output_folder = f"{DefaultPaths.drive_path}/text_history"
@@ -261,30 +265,32 @@ def text_main():
f.write(file_content)
print(dt_string + " log save")
- col1, col2 = st.columns([.075,1])
- with col1:
- heart_button = st.form_submit_button(label="💗 喜欢", on_click=add_heart_item)
- with col2:
- url = 'https://drive.google.com/drive/folders/'+fid
- print("url: "+url)
-
- from bokeh.models.widgets import Div
- if st.form_submit_button('📜 历史记录'):
- js = "window.open('" + url + "')" # New tab or window
- print(js)
- html = ''.format(js)
- div = Div(text=html)
- st.bokeh_chart(div)
+
+ url = 'https://drive.google.com/drive/folders/'+fid
+ print("url: "+url)
+
+ from bokeh.models.widgets import Div
+ if st.form_submit_button('📜 历史记录'):
+ # New tab or window
+ js = "window.open('" + url + "')"
+ print(js)
+ html = ''.format(js)
+ div = Div(text=html)
+ st.bokeh_chart(div)
# st.write(
# f'
',
# unsafe_allow_html=True,
# )
+ heart_button = st.form_submit_button(
+ label="💗 喜欢", on_click=add_heart_item)
+
+
text_main()
placeholder = st.empty()
with placeholder.container():
- st.write(" ")
+ st.write(" ")
st.subheader('🎨 让AI画画 [文本生成图像]')
page_names = ["[完成度更高] CLIP Guided Diffusion", "[更有创造力] VQGAN+CLIP"]
@@ -301,7 +307,7 @@ def text_main():
if "user_input_ch" not in st.session_state:
st.session_state.user_input_ch = "一幅由greg rutkowski和thomas kinkade创作的奇异灯塔的美丽画作,将其光芒照耀在一片动荡的血海中|artstation上的趋势|赛博朋克色彩方案"
-
+
user_input_ch = st.text_input(
"总结AI的回复,输入你喜欢的具有特征性的[词组]来生成图像",
@@ -312,7 +318,6 @@ def text_main():
# st.write(user_input)
-
def add_to_prompt(text):
global user_input_ch
st.session_state.user_input_ch = user_input_ch + " " + text
@@ -335,7 +340,13 @@ def dimensions_compatibility(type, after):
enhancers = st.expander("试试添加这些风格类的形容词 Prompt enhancers (可选)")
with enhancers:
st.write(
- "在你的文本中增加一些风格类词组,可以产生更多样的结果。下面是一些可以产生有趣的结果的例子。你可以在
这里 了解更多关于Prompt Engineering提示词改造的信息。",
+ '''在你的文本中增加一些风格类词组,可以产生更多样的结果。下面是一些可以产生有趣的结果的例子,你可以点选以添加到你的文本中。
+ 可以看看这些链接
+
1 /
+
2 /
+
3 /
+
4 /
+
5 ,了解更多关于提示词改造(Prompt Engineering)的信息。''',
unsafe_allow_html=True,
)
with st.container():
@@ -552,7 +563,6 @@ def dimensions_compatibility(type, after):
elif sampling_mode == "生成速度更快且质量较好 plms":
sampling_mode = "plms"
-
sat_scale = col2.number_input(
"图像饱和度 Sat scale",
value=0,
@@ -568,7 +578,8 @@ def dimensions_compatibility(type, after):
value=0.8,
help="eta(希腊字母η)是一个diffusion模型的变量,它在每个时间步长(timestep)中混入随机量的比例噪声。0是没有噪音,1.0是更多的噪音。",
)
- clamp_max = col2.number_input("梯度裁剪最大值 Clamp max", value=0.05, help="")
+ clamp_max = col2.number_input(
+ "梯度裁剪最大值 Clamp max", value=0.05, help="")
use_augs = col2.checkbox(
"使用args",
@@ -655,8 +666,8 @@ def dimensions_compatibility(type, after):
default=["ViT-B/32"],
help="选择你想在你的作品中使用的CLIP模型。如果你没有Colab Pro,你可能不希望选择ViT-L/14 或者 RN50x64",
)
- seed = col1.number_input("随机种子值", value=init_seed, step=1,
- help="选择随机种子值,增加生成的随机性。")
+ seed = col1.number_input("随机种子值", value=init_seed, step=1,
+ help="选择随机种子值,增加生成的随机性。")
# template = col1.select("Template")
# learning_rate = col1.number_input(
# "Learning rate",
@@ -702,7 +713,7 @@ def dimensions_compatibility(type, after):
],
index=3,
)
-
+
if template == "无 none":
template = "none"
elif template == "平衡 Balanced":
@@ -719,7 +730,7 @@ def dimensions_compatibility(type, after):
template = "Subtle MSE"
elif template == "快速生成 Hyper Fast Results":
template = "Hyper Fast Results"
-
+
mse = col1.checkbox(
"开启 MSE regularization",
value=True,
@@ -745,7 +756,6 @@ def dimensions_compatibility(type, after):
)
-
with gensettings:
intermediary_frames = st.checkbox("保存中间帧", value=False)
if intermediary_frames:
@@ -829,14 +839,14 @@ def run_internal(args, status, stoutput, gray_during_execution):
if os.listdir(output_folder):
files_path = os.path.join(output_folder, "*.png")
files = sorted(glob.iglob(files_path),
- key=os.path.getctime, reverse=True)
+ key=os.path.getctime, reverse=True)
try:
gallery_text_area.write("又见面啦!你上一次的创作:")
- gallery_image_area.image(Image.open(files[0]))
+ gallery_image_area.image(Image.open(files[0]))
except:
gallery_text_area = st.empty()
gallery_image_area = st.empty()
- url='https://drive.google.com/drive/folders/'+fid
+ url = 'https://drive.google.com/drive/folders/'+fid
from bokeh.models.widgets import Div
if st.form_submit_button('在Google Drive上查看你的生成作品'):
js = "window.open('" + url + "')" # New tab or window
@@ -844,7 +854,7 @@ def run_internal(args, status, stoutput, gray_during_execution):
html = '
'.format(js)
div = Div(text=html)
st.bokeh_chart(div)
-
+
# st.write(
# f'
',
# #
We do not collect prompts or results. Your creations don\'t belong to MindsEye. Read our FAQ.
Feel free to reference #MindsEye and tag @multimodalart when sharing your creations if you wish',
@@ -890,7 +900,8 @@ def intermediary_frame_setup(seed):
gray_during_execution = st.empty()
if submit:
- user_input = str(translator.translate_text(user_input_ch, target_lang="EN-GB"))# st.write(user_input)
+ user_input = str(translator.translate_text(
+ user_input_ch, target_lang="EN-GB")) # st.write(user_input)
meta_status = col_output2.empty()
status = col_output2.empty()
if uploaded_file is not None:
@@ -901,7 +912,8 @@ def intermediary_frame_setup(seed):
image_path = uploaded_file.name
else:
image_path = None
- intermediary_folder,video_frame_folder, update_every = intermediary_frame_setup(seed)
+ intermediary_folder, video_frame_folder, update_every = intermediary_frame_setup(
+ seed)
if page == "[更有创造力] VQGAN+CLIP":
args = argparse.Namespace(
@@ -931,8 +943,8 @@ def intermediary_frame_setup(seed):
how_many_frames=how_many_frames,
generate_video=generate_video,
video_frame_folder=video_frame_folder,
- CH_version = True,
- CH_prompt = user_input_ch
+ CH_version=True,
+ CH_prompt=user_input_ch
)
elif page == "[完成度更高] CLIP Guided Diffusion":
args = argparse.Namespace(
@@ -1000,14 +1012,14 @@ def intermediary_frame_setup(seed):
how_many_frames=how_many_frames,
generate_video=generate_video,
video_frame_folder=video_frame_folder,
- CH_version = True,
- CH_prompt = user_input_ch
+ CH_version=True,
+ CH_prompt=user_input_ch
)
try:
if (how_many_runs) > 1:
if batch_folder:
DefaultPaths.output_path = f"{DefaultPaths.output_path}/{batch_folder}"
- intermediary_folder,video_frame_folder, update_every = intermediary_frame_setup(
+ intermediary_folder, video_frame_folder, update_every = intermediary_frame_setup(
args.seed)
for i in range(how_many_runs):
if how_many_runs > 1:
@@ -1016,7 +1028,7 @@ def intermediary_frame_setup(seed):
if i > 0:
if randomize_seed:
args.seed = random.randint(0, 2147483647)
- intermediary_folder,video_frame_folder, update_every = intermediary_frame_setup(
+ intermediary_folder, video_frame_folder, update_every = intermediary_frame_setup(
args.seed)
args.frame_dir = intermediary_folder
run_internal(args, status, col_output2, gray_during_execution)
@@ -1035,7 +1047,7 @@ def intermediary_frame_setup(seed):
st.session_state.seed = init_seed
meta_status.empty()
st.experimental_rerun()
-
+
footer = """
"""
st.markdown(footer, unsafe_allow_html=True)
-st.write(custom_css, unsafe_allow_html=True)
\ No newline at end of file
+st.write(custom_css, unsafe_allow_html=True)
diff --git a/ai-atelier.py b/ai-atelier.py
index 6592a87..3246a52 100644
--- a/ai-atelier.py
+++ b/ai-atelier.py
@@ -19,8 +19,9 @@
import requests
import webbrowser
from kora.xattr import get_id
-from setup import textsynth_completion
-# from setup_mac import textsynth_completion
+
+# from setup import textsynth_completion
+from setup_mac import textsynth_completion
torch.cuda.empty_cache()
@@ -108,6 +109,7 @@
st.set_page_config(page_title=" AI Atelier", page_icon="🔮", layout="wide",)
+
class DefaultPaths:
root_path = f"."
if not (path_exists(f"/content/drive/MyDrive/")):
@@ -146,7 +148,7 @@ def add_heart_item():
def open_history_log():
from kora.xattr import get_id
-
+
if DefaultPaths.is_drive:
output_folder = f"{DefaultPaths.drive_path}/text_history"
if not path_exists(output_folder):
@@ -219,7 +221,8 @@ def text_main():
with st.spinner('Generating...'):
- res = textsynth_completion(prompt, api_engine, max_tokens, top_k, top_p, stop, temperature)
+ res = textsynth_completion(
+ prompt, api_engine, max_tokens, top_k, top_p, stop, temperature)
# print("\nQ: " + user_input + '\nA: ' + res)
# st.balloons()
@@ -249,16 +252,18 @@ def text_main():
f.write(file_content)
print(dt_string + " log save")
- col1, col2 = st.columns([.072,1])
+ col1, col2 = st.columns([.072, 1])
with col1:
- heart_button = st.form_submit_button(label="💗 Like", on_click=add_heart_item)
+ heart_button = st.form_submit_button(
+ label="💗 Like", on_click=add_heart_item)
with col2:
url = 'https://drive.google.com/drive/folders/'+fid
print("url: "+url)
from bokeh.models.widgets import Div
if st.form_submit_button('📜 History'):
- js = "window.open('" + url + "')" # New tab or window
+ # New tab or window
+ js = "window.open('" + url + "')"
print(js)
html = '
'.format(js)
div = Div(text=html)
@@ -275,7 +280,7 @@ def text_main():
placeholder = st.empty()
with placeholder.container():
- st.write(" ")
+ st.write(" ")
st.subheader('🎨 Let AI draw [text-to-image]')
page_names = ["[Coherent] CLIP Guided Diffusion", "[Artistic] VQGAN+CLIP"]
@@ -321,7 +326,13 @@ def dimensions_compatibility(type, after):
enhancers = st.expander("Prompt enhancers (optional)")
with enhancers:
st.write(
- "Adding enhancers to your prompts can produce very different results to the generated images, the few below are some examples that can produce interesting results.
Here you can learn more about Prompt Engineering",
+ '''Adding enhancers to your prompts can produce very different results to the generated images, the few below are some examples that can produce interesting results.
+ You can learn more about Prompt Engineering from the following links.
+
1 /
+
2 /
+
3 /
+
4 /
+
5 ''',
unsafe_allow_html=True,
)
with st.container():
@@ -708,7 +719,6 @@ def dimensions_compatibility(type, after):
)
-
with gensettings:
intermediary_frames = st.checkbox("Save intermediary frames", value=False)
if intermediary_frames:
@@ -792,14 +802,14 @@ def run_internal(args, status, stoutput, gray_during_execution):
if os.listdir(output_folder):
files_path = os.path.join(output_folder, "*.png")
files = sorted(glob.iglob(files_path),
- key=os.path.getctime, reverse=True)
+ key=os.path.getctime, reverse=True)
try:
gallery_text_area.write("Your last creation:")
- gallery_image_area.image(Image.open(files[0]))
+ gallery_image_area.image(Image.open(files[0]))
except:
gallery_text_area = st.empty()
- gallery_image_area = st.empty()
- url='https://drive.google.com/drive/folders/'+fid
+ gallery_image_area = st.empty()
+ url = 'https://drive.google.com/drive/folders/'+fid
from bokeh.models.widgets import Div
if st.form_submit_button('View your gallery on Google Drive'):
js = "window.open('" + url + "')" # New tab or window
@@ -818,7 +828,8 @@ def run_internal(args, status, stoutput, gray_during_execution):
#
We do not collect prompts or results. Your creations don\'t belong to MindsEye. Read our FAQ.
Feel free to reference #MindsEye and tag @multimodalart when sharing your creations if you wish ',
unsafe_allow_html=True,
)
- st.write("Right-click to download your generated images and videos directly from Google Drive")
+ st.write(
+ "Right-click to download your generated images and videos directly from Google Drive")
if os.path.exists("progress.png"):
gallery_text_area.write("Your last creation:")
gallery_image_area.image(Image.open("progress.png"))
@@ -862,7 +873,8 @@ def intermediary_frame_setup(seed):
image_path = uploaded_file.name
else:
image_path = None
- intermediary_folder,video_frame_folder, update_every = intermediary_frame_setup(seed)
+ intermediary_folder, video_frame_folder, update_every = intermediary_frame_setup(
+ seed)
if page == "[Artistic] VQGAN+CLIP":
args = argparse.Namespace(
@@ -892,8 +904,8 @@ def intermediary_frame_setup(seed):
how_many_frames=how_many_frames,
generate_video=generate_video,
video_frame_folder=video_frame_folder,
- CH_version = False,
- CH_prompt = ""
+ CH_version=False,
+ CH_prompt=""
)
elif page == "[Coherent] CLIP Guided Diffusion":
args = argparse.Namespace(
@@ -961,14 +973,14 @@ def intermediary_frame_setup(seed):
how_many_frames=how_many_frames,
generate_video=generate_video,
video_frame_folder=video_frame_folder,
- CH_version = False,
- CH_prompt = ""
+ CH_version=False,
+ CH_prompt=""
)
try:
if (how_many_runs) > 1:
if batch_folder:
DefaultPaths.output_path = f"{DefaultPaths.output_path}/{batch_folder}"
- intermediary_folder,video_frame_folder, update_every = intermediary_frame_setup(
+ intermediary_folder, video_frame_folder, update_every = intermediary_frame_setup(
args.seed)
for i in range(how_many_runs):
if how_many_runs > 1:
@@ -977,7 +989,7 @@ def intermediary_frame_setup(seed):
if i > 0:
if randomize_seed:
args.seed = random.randint(0, 2147483647)
- intermediary_folder,video_frame_folder, update_every = intermediary_frame_setup(
+ intermediary_folder, video_frame_folder, update_every = intermediary_frame_setup(
args.seed)
args.frame_dir = intermediary_folder
run_internal(args, status, col_output2, gray_during_execution)
@@ -996,7 +1008,7 @@ def intermediary_frame_setup(seed):
st.session_state.seed = init_seed
meta_status.empty()
st.experimental_rerun()
-
+
footer = """
"""
st.markdown(footer, unsafe_allow_html=True)
-st.write(custom_css, unsafe_allow_html=True)
\ No newline at end of file
+st.write(custom_css, unsafe_allow_html=True)
From bc3edd43eacc7594cd80f872b0beaaf30947e512 Mon Sep 17 00:00:00 2001
From: Muhan Xu <53051442+ryananan@users.noreply.github.com>
Date: Sun, 24 Apr 2022 17:25:52 +0800
Subject: [PATCH 2/6] Update ai-atelier.py
---
ai-atelier.py | 63 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 23 deletions(-)
diff --git a/ai-atelier.py b/ai-atelier.py
index 3246a52..a0c4459 100644
--- a/ai-atelier.py
+++ b/ai-atelier.py
@@ -21,6 +21,11 @@
from kora.xattr import get_id
# from setup import textsynth_completion
+<<<<<<< Updated upstream
+=======
+
+# For debug in mac
+>>>>>>> Stashed changes
from setup_mac import textsynth_completion
torch.cuda.empty_cache()
@@ -41,8 +46,12 @@
/*Generate your answers button*/
.appview-container > section > div > div > div > div.css-1p05t8e.epcbefy1 > div:nth-child(1) > div > div > div > div > button{color: #B6A4FC}
-/*history link
-.appview-container > section > div > div > div > div.css-1p05t8e.epcbefy1 > div:nth-child(1) > div > div.css-ocqkz7.e1tzin5v0 > div.css-y5mkj7.e1tzin5v2 {color: rgb(209 209 209 / 75%); padding:0px; position:relative; top:4px}*/
+/*history link*/
+.appview-container > section > div > div:nth-child(1) > div > div:nth-child(6) > div:nth-child(1) > div > div:nth-child(4){position: relative; left: 100px; top: 2px}
+
+/*like and history button text colour*/
+.appview-container > section > div > div:nth-child(1) > div > div:nth-child(6) > div:nth-child(1) > div > div:nth-child(5) > div > div > button{color: rgb(209 209 209 / 100%)}
+.appview-container > section > div > div:nth-child(1) > div > div:nth-child(6) > div:nth-child(1) > div > div:nth-child(4){color: rgb(209 209 209 / 100%)}
# .css-ffhzg2 div[data-testid="stExpander"]{background-color: rgb(14, 17, 23)}
# .css-fg4pbf div[data-testid="stExpander"]{background-color: white}
@@ -132,6 +141,14 @@ class DefaultPaths:
)
st.subheader('💬 Ask AI [text-to-text]')
+def open_history(url):
+ from bokeh.models.widgets import Div
+ # New tab
+ js = "window.open('" + url + "')"
+ print(js)
+ html = '