FAW-AI-APP / gen_tab.py
JarvisLabs's picture
Upload 140 files
b283998 verified
import gradio as gr
from src.utils import add_to_prompt
from src.rep_api import generate_image_replicate,generate_image_control_net, model_dict
import os
# The dictionary data
prompt_dict = {
"Character": ["Asian girl with black hair", "A man with blond hair", "A Cat girl anime character with purple hair", "A Green Alien with big black eyes"],
"Clothes": ["Wearing a blue jacket", "Wearing a black business suit", "Wearing a purple jumpsuit", "Wearing shorts and a white T-shirt"],
"Pose": ["Close up portrait", "Standing doing a peace sign", "Folding arms", "holding a phone"],
"Style": ["Simple white background", "Fashion runway", "Inside a business conference", "Inside a spaceship"],
}
prompt_dict_kp ={
"Character": ["黒髪のアジア系女性", "金髪の男性", "紫髪のキャットガールアニメキャラクター", "大きな黒い目を持つ緑の宇宙人"],
"Clothes": ["青いジャケットを着ている", "黒のビジネススーツを着ている", "紫のジャンプスーツを着ている", "ショーツと白いTシャツを着ている"],
"Pose": ["クローズアップポートレート", "ピースサインをして立っている", "腕を組んでいる", "携帯電話を持っている"],
"Scene": ["シンプルな白背景", "ファッションランウェイ", "ビジネス会議の中", "宇宙船の内部"]
}
lora_style_support = [
["ps1","Test_images/lora_support_examples/ps1.png"],
["cyberpunk","Test_images/lora_support_examples/cyberpunk.png"],
["Sioux","Test_images/Walk_4.png"],
["RetroAnime1","Test_images/lora_support_examples/appleseed.png"],
["RetroAnime2","Test_images/lora_support_examples/Galverse.png"],
["half-illustration","Test_images/lora_support_examples/halfillust.png"]
]
prompt_support = [
["Test_images/prompt_support_examples/Man_1.png","A full body photo man standing with blond hair wearing a suit"],
["Test_images/prompt_support_examples/Woman_1.png","A full body photo girl standing with blond hair wearing a suit "],
["Test_images/prompt_support_examples/Woman_2.png","a Asian girl as at a fashion show walking down the cat walk, wearing a red dress"],
["Test_images/prompt_support_examples/Man_2.png","A High exposure photo of a Asian man wearing a blue shirt at a business conference, blue shirt, short black hair, hands out welcoming people into a booth, booth with a green and white color scheme "],
["Test_images/prompt_support_examples/Shoes_1.png","a product photo of high tech shoes with lights and a wifi symbol on the side, low angle shot, front view of walking down stairs "],
["Test_images/prompt_support_examples/Jacket_1.png","a product photo of green checked jacked being on a man from behind , furry collar, large cute character logo of a cat on back of jacket, simple background,"],
]
def create_gen_tab():
with gr.TabItem("Image Generator"):
#Gen how too row
with gr.Row():
with gr.Accordion("HowTo",open=False):
with gr.Column():
gr.Markdown("### How to use the Image Generator 画像生成器の使い方 \n"
"1. Enter a prompt in the textbox. テキストボックスにプロンプトを入力します。\n"
"2. Choose the aspect ratio. アスペクト比を選択します。\n"
"3. Options Select a style lore. スタイルロアを選択します。\n"
"4. Options in extra control net. Extraでコントロールネットのオプションを選択します。\n"
"5. Click 'Generate' to create the image. Generateをクリックして画像を生成します。\n"
"6. click button to move image to other tab.ボタンをクリックして画像を他のタブに移動します。 \n")
gr.Image(value="HowTo/Gen.png",label=None,interactive=False)
#Gen generatpor options
with gr.Row():
with gr.Column():
inp = gr.Textbox(label="Prompt",info="日本語対応は可能")
aspect_ratio = gr.Dropdown(list(["1:1","16:9","9:16","5:4"]),value="1:1", label="Aspect Ratio", info="Image size Aspect Ratio 画像サイズ アスペクト比")
with gr.Accordion("Control Net", open=False):
#Control net
use_control_net=gr.Checkbox(label="Use Control net",value=False)
control_net_type=gr.Dropdown(["depth","canny","soft_edge"],value="depth",label="Control net type")
control_net_img= gr.Image(label="Control net image",type="pil")
control_net_strength = gr.Slider(0,1,value=0.4,label="control net strength")
control_net_examples = gr.Examples(
examples=["Test_images/Walk_3.png","Test_images/example_outputs/input_2.png","Test_images/example_outputs/input_4.png","Test_images/Sit_1.png","Test_images/controlnet-in-automatic1111-for-character-design-sheets-v0-ir6p0gdwpfia1.webp"],
inputs=[control_net_img]
)
with gr.Column():
style_mode = gr.Dropdown(list(model_dict.keys()),label="Style lore",value="Base",info="style model スタイルのモデル")
with gr.Accordion("Style Imgaes",open=False):
# with gr.Column(elem_id="prompt_support_column"):
for i,lora in enumerate(lora_style_support):
if i % 3 == 0:
row = gr.Row() # Start a new row
with row:
lora_img = gr.Image(value=lora[1], label=lora[0],width=200,height=200, interactive=False)
lora_img.select(lambda x:x, inputs=gr.Textbox(value=lora[0],visible=False),outputs=style_mode)
api_path = gr.Textbox(label="Other_style",info="Style lora .safetensors route goes here or replicate link goes here スタイルのローラの.safetensorsのルートはこちら。",value=None)
style_strength = gr.Slider(0,2,value=1,label="Style Strength")
with gr.Row():
btn = gr.Button("Generate")
with gr.Accordion("Prompt Support", open=False):
for i,item in enumerate(prompt_support):
if i % 6 ==0:
row=gr.Row()
with row:
with gr.Column(elem_id="prompt_support_column"):
img_ps=gr.Image(value=item[0],label="",interactive=False)
btn_ps=gr.Button(item[1],elem_id="prompt_support_button")
img_ps.select(lambda x:x, inputs=gr.Textbox(item[1],visible=False),outputs=inp)
btn_ps.click(lambda x:x, inputs=gr.Textbox(item[1],visible=False),outputs=inp)
with gr.Row():
gen_out = gr.Image(label="Generated Image",type="filepath",elem_id="output_image")
with gr.Row(): #Move gen out row
move_to_ip =gr.Button("Move to Cloth IP Adapter")
move_to_vto =gr.Button("Move to Virtual Try On")
move_to_cnmk =gr.Button("Move to Control net mockup ")
move_to_relight= gr.Button("Move to Relight")
# move_to_fs =gr.Button("Move to Face Swap")
# move_to_zest=gr.Button("Move to Zest IP Adapter")
btn.click(generate_image_control_net,
inputs=[inp,style_mode,api_path,aspect_ratio,style_strength,use_control_net,control_net_type,control_net_img,control_net_strength],
outputs=[gen_out])
return gen_out,move_to_vto,move_to_ip,move_to_cnmk,move_to_relight# move_to_fs,#,move_to_zest