File size: 3,607 Bytes
80e8f8f
 
 
c3b559f
09c2e1a
 
 
 
 
 
80e8f8f
 
15d24fa
80e8f8f
 
 
 
 
 
 
 
 
afc86b4
80e8f8f
 
 
 
 
 
afc86b4
c3b559f
50dd30b
15d24fa
891db97
 
80e8f8f
 
 
 
 
 
 
 
9ee132a
80e8f8f
 
9ee132a
80e8f8f
 
2708475
80e8f8f
 
638d5bf
80e8f8f
 
 
 
 
 
 
 
 
 
 
 
 
2193b3e
80e8f8f
 
 
 
 
 
 
 
 
 
 
 
 
 
1fa8f79
80e8f8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import gradio as gr
import requests
import os
from PIL import Image
from io import BytesIO
import base64

def error_str(error, title="Error"):
    return f"""#### {title}
            {error}"""  if error else ""

def inference(prompt, guidance, steps, image_size="Landscape", seed=0, img=None, strength=0.5, neg_prompt="", disable_auto_prompt_correction=False):
  try:
    response = requests.post(os.environ["BACKEND"], json={
    	"data": [
    		prompt,
    		guidance,
    		steps,
    		image_size,
    		seed,
    		img,
    		strength,
    		neg_prompt,
    		disable_auto_prompt_correction,
    	]
    }).json()

    data = response["data"]
    
    image=Image.open(BytesIO(base64.b64decode(data[0].split(',')[1])))

    return image,data[1],data[2]
  except Exception as e:
    print(error_str(e))
    return None, "Error", "Error"

css = """.main-div div{display:inline-flex;align-items:center;gap:.8rem;font-size:1.75rem}.main-div div h1{font-weight:900;margin-bottom:7px}.main-div p{margin-bottom:10px;font-size:94%}a{text-decoration:underline}.tabs{margin-top:0;margin-bottom:0}#gallery{min-height:20rem}
"""
with gr.Blocks(css=css) as demo:
    gr.HTML(
        f"""
            <div class="main-div">
              <div>
                <h1>ChatEmi Beta デモ</h1>
              </div>
              <p>
              個人情報などは入れないでください。
              </p>
              <p>
              サンプルプロンプト1:黒い髪の美少女の顔アップ
              </p>
              <p>
              サンプルプロンプト2:白い髪の男性の上半身
              </p>
            </div>
        """
    )
    with gr.Row():
        
        with gr.Column(scale=55):
          with gr.Group():
              
              with gr.Row():
                prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="[your prompt]")
                generate = gr.Button(value="Generate")

              image_out = gr.Image(height=1024,width=1024)
          error_output = gr.Markdown()

        with gr.Column(scale=45):
          with gr.Tab("Options"):
            with gr.Group():
              neg_prompt = gr.Textbox(label="Negative prompt", placeholder="What to exclude from the image")
              disable_auto_prompt_correction = gr.Checkbox(label="Disable auto prompt corretion.")
              with gr.Row():
                image_size=gr.Radio(["Portrait","Landscape","Square"])
                image_size.show_label=False
                image_size.value="Square"
                
              with gr.Row():
                guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=25)
                steps = gr.Slider(label="Steps", value=20, minimum=2, maximum=30, step=1)

              seed = gr.Slider(0, 2147483647, label='Seed (0 = random)', value=0, step=1)
              prompt_display= gr.Textbox(label="Upsampled prompt", interactive=False)

          with gr.Tab("Image to image"):
              with gr.Group():
                image = gr.Image(label="Image", height=256, tool="editor", type="pil")
                strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
                  
    inputs = [prompt, guidance, steps, image_size, seed, image, strength, neg_prompt, disable_auto_prompt_correction]

    outputs = [image_out, error_output, prompt_display]
    prompt.submit(inference, inputs=inputs, outputs=outputs)
    generate.click(inference, inputs=inputs, outputs=outputs)
    
demo.queue(concurrency_count=1)
demo.launch()