Spaces:
Running
Running
ehristoforu
commited on
Commit
•
f387fa4
1
Parent(s):
261228d
Create app-colab.py
Browse files- app-colab.py +132 -0
app-colab.py
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import requests
|
4 |
+
import time
|
5 |
+
import os
|
6 |
+
import argparse
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
load_dotenv("config.txt")
|
10 |
+
|
11 |
+
from engine.generate import gpugen
|
12 |
+
from engine.upscaler import upscale_image
|
13 |
+
from engine.promptGenerator import prompting
|
14 |
+
|
15 |
+
|
16 |
+
css = """
|
17 |
+
#container{
|
18 |
+
margin: 0 auto;
|
19 |
+
max-width: 40rem;
|
20 |
+
}
|
21 |
+
#intro{
|
22 |
+
max-width: 100%;
|
23 |
+
text-align: center;
|
24 |
+
margin: 0 auto;
|
25 |
+
}
|
26 |
+
#generate_button {
|
27 |
+
color: white;
|
28 |
+
border-color: #007bff;
|
29 |
+
background: #007bff;
|
30 |
+
width: 200px;
|
31 |
+
height: 50px;
|
32 |
+
}
|
33 |
+
footer {
|
34 |
+
visibility: hidden
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
with gr.Blocks(title="Rensor", css=css, theme="ehristoforu/RE_Theme") as webui:
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Row(visible=False, variant="panel") as prompter:
|
41 |
+
with gr.Column(scale=1):
|
42 |
+
chatbot = gr.Textbox(show_label=False, interactive=False, max_lines=16, lines=14)
|
43 |
+
with gr.Row():
|
44 |
+
chat_text = gr.Textbox(show_label=False, placeholder="Enter short prompt", max_lines=2, lines=1, interactive=True, scale=20)
|
45 |
+
chat_submit = gr.Button(value="Prompt", scale=1)
|
46 |
+
|
47 |
+
chat_submit.click(fn=lambda x: gr.update(value="Prompting...", interactive=False), inputs=chat_submit, outputs=chat_submit).then(prompting, inputs=chat_text, outputs=chatbot).then(fn=lambda x: gr.update(value="Prompt", interactive=True), inputs=chat_submit, outputs=chat_submit)
|
48 |
+
|
49 |
+
|
50 |
+
with gr.Column(scale=3):
|
51 |
+
with gr.Row():
|
52 |
+
gallery = gr.Gallery(show_label=False, rows=2, columns=6, preview=True, value=["assets/favicon.png"])
|
53 |
+
work_time = gr.Markdown(visible=False)
|
54 |
+
with gr.Row():
|
55 |
+
prompt = gr.Textbox(show_label=False, placeholder="Your amazing prompt...", max_lines=3, lines=3, interactive=True, scale=18)
|
56 |
+
button = gr.Button(value="Generate", variant="primary", scale=1)
|
57 |
+
with gr.Row():
|
58 |
+
advenced = gr.Checkbox(label="Advanced inputs/settings", value=False, interactive=True)
|
59 |
+
prompter_change = gr.Checkbox(label="Prompter", value=False, interactive=True)
|
60 |
+
|
61 |
+
|
62 |
+
with gr.Row(visible=False, variant="panel") as settings_tab:
|
63 |
+
with gr.Column(scale=1):
|
64 |
+
with gr.Tab("Settings"):
|
65 |
+
with gr.Row(scale=10):
|
66 |
+
mode = gr.Radio(label="Mode", choices=["High Quality", "Fast", "Super-fast"], value="Fast", info="Relationship between generation speed and quality.", interactive=True, visible=True)
|
67 |
+
with gr.Row(scale=10):
|
68 |
+
width = gr.Slider(label="Width", maximum=2048, minimum=256, value=512, step=8, interactive=True, visible=True)
|
69 |
+
height = gr.Slider(label="Height", maximum=2048, minimum=256, value=512, step=8, interactive=True, visible=True)
|
70 |
+
with gr.Row(scale=10):
|
71 |
+
guidance = gr.Slider(label="Guidance Scale", maximum=20.0, minimum=0.0, value=8.0, step=0.1, interactive=True, visible=True)
|
72 |
+
with gr.Row(scale=10):
|
73 |
+
num_images = gr.Slider(label="Number of images", maximum=12, minimum=1, value=1, step=1, interactive=True, visible=True)
|
74 |
+
with gr.Row(scale=1):
|
75 |
+
upscale_button = gr.Image(label="🚀 Upload image to 2x upscale", sources="upload", type="numpy", show_download_button=False, interactive=True)
|
76 |
+
|
77 |
+
with gr.Tab("Init image"):
|
78 |
+
with gr.Row():
|
79 |
+
with gr.Column():
|
80 |
+
img2img_change = gr.Checkbox(label="Init Image", value=False, visible=True, interactive=True, scale=10)
|
81 |
+
i2i_strength = gr.Slider(label="Init Strength", minimum=0.01, maximum=2, step=0.01, value=0.70, interactive=False, visible=True)
|
82 |
+
init_image = gr.Image(label="Init image", type="pil", interactive=False, visible=True, scale=1)
|
83 |
+
with gr.Tab("Inpaint"):
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
inpaint_change = gr.Checkbox(label="Inpaint", value=False, visible=True, interactive=True, scale=4)
|
87 |
+
inpaint_strength = gr.Slider(label="Inpaint Strength", minimum=0.01, maximum=2, step=0.01, value=0.70, interactive=False, visible=True)
|
88 |
+
inpaint_image = gr.Image(label="Inpaint image", type="pil", interactive=False, visible=True, tool="sketch", scale=1)
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
button.click(fn=lambda x: gr.update(visible=False), inputs=work_time, outputs=work_time).then(fn=lambda x: gr.update(value="Generating...", variant="secondary", interactive=False), inputs=button, outputs=button).then(gpugen, inputs=[prompt, mode, guidance, width, height, num_images, i2i_strength, inpaint_strength, img2img_change, inpaint_change, init_image, inpaint_image], outputs=[gallery, work_time]).then(fn=lambda x: gr.update(visible=True), inputs=work_time, outputs=work_time).then(fn=lambda x: gr.update(value="Generate", variant="primary", interactive=True), inputs=button, outputs=button)
|
93 |
+
|
94 |
+
upscale_button.upload(fn=lambda x: gr.update(visible=False), inputs=work_time, outputs=work_time).then(fn=lambda x: gr.update(label="🖼️ Image uploaded to 2x upscale", interactive=False), inputs=upscale_button, outputs=upscale_button).then(fn=lambda x: gr.update(value="Upscaling...", variant="secondary", interactive=False), inputs=button, outputs=button).then(upscale_image, inputs=upscale_button, outputs=[gallery, work_time]).then(fn=lambda x: gr.update(label="🚀 Upload image to 2x upscale", interactive=True), inputs=upscale_button, outputs=upscale_button).then(fn=lambda x: gr.update(value="Generate", variant="primary", interactive=True), inputs=button, outputs=button).then(fn=lambda x: gr.update(visible=True), inputs=work_time, outputs=work_time)
|
95 |
+
|
96 |
+
advenced.change(fn=lambda x: gr.update(visible=x), inputs=advenced, outputs=settings_tab, queue=False, api_name=False)
|
97 |
+
prompter_change.change(fn=lambda x: gr.update(visible=x), inputs=prompter_change, outputs=prompter, queue=False, api_name=False)
|
98 |
+
|
99 |
+
|
100 |
+
img2img_change.change(
|
101 |
+
fn=lambda x: gr.update(interactive=x),
|
102 |
+
inputs=img2img_change,
|
103 |
+
outputs=init_image,
|
104 |
+
queue=False,
|
105 |
+
api_name=False,
|
106 |
+
).then(
|
107 |
+
fn=lambda x: gr.update(interactive=x),
|
108 |
+
inputs=img2img_change,
|
109 |
+
outputs=i2i_strength,
|
110 |
+
queue=False,
|
111 |
+
api_name=False,
|
112 |
+
)
|
113 |
+
|
114 |
+
|
115 |
+
inpaint_change.change(
|
116 |
+
fn=lambda x: gr.update(interactive=x),
|
117 |
+
inputs=inpaint_change,
|
118 |
+
outputs=inpaint_image,
|
119 |
+
queue=False,
|
120 |
+
api_name=False,
|
121 |
+
).then(
|
122 |
+
fn=lambda x: gr.update(interactive=x),
|
123 |
+
inputs=inpaint_change,
|
124 |
+
outputs=inpaint_strength,
|
125 |
+
queue=False,
|
126 |
+
api_name=False,
|
127 |
+
)
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
webui.queue(max_size=20).launch(debug=False, share=True, server_port=5555, quiet=True, show_api=False, favicon_path="assets/favicon.png", inbrowser=True)
|