Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from stablepy import Model_Diffusers
|
3 |
+
|
4 |
+
|
5 |
+
# Define the function to generate images
|
6 |
+
def generate_image(prompt, num_steps, guidance_scale, sampler, img_width, img_height, upscaler_model_path, upscaler_increases_size, hires_steps, base_model_id):
|
7 |
+
|
8 |
+
model = Model_Diffusers(
|
9 |
+
base_model_id=base_model_id,
|
10 |
+
task_name='txt2img',
|
11 |
+
)
|
12 |
+
|
13 |
+
image, info_image = model(
|
14 |
+
prompt=prompt,
|
15 |
+
num_steps=num_steps,
|
16 |
+
guidance_scale=guidance_scale,
|
17 |
+
sampler=sampler,
|
18 |
+
img_width=img_width,
|
19 |
+
img_height=img_height,
|
20 |
+
upscaler_model_path=upscaler_model_path,
|
21 |
+
upscaler_increases_size=upscaler_increases_size,
|
22 |
+
hires_steps=hires_steps,
|
23 |
+
)
|
24 |
+
return image[0]
|
25 |
+
|
26 |
+
# Create the Gradio Blocks UI
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("# StablePY")
|
29 |
+
|
30 |
+
moelpah = gr.Textbox(label="model", placeholder="user/repo")
|
31 |
+
|
32 |
+
with gr.Row():
|
33 |
+
prompt = gr.Textbox(label="Prompt", value="highly detailed portrait of an underwater city, with towering spires and domes rising up from the ocean floor")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
num_steps = gr.Slider(label="Number of Steps", minimum=1, maximum=100, value=30)
|
37 |
+
guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, value=7.5)
|
38 |
+
sampler = gr.Dropdown(label="Sampler", choices=["DPM++ 2M", "DDIM", "Euler A"], value="DPM++ 2M")
|
39 |
+
|
40 |
+
with gr.Row():
|
41 |
+
img_width = gr.Number(label="Image Width", value=1024)
|
42 |
+
img_height = gr.Number(label="Image Height", value=1024)
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
upscaler_model_path = gr.Textbox(label="Upscaler Model Path", value="./upscaler/RealESRGAN_x4plus_anime_6B.pth")
|
46 |
+
upscaler_increases_size = gr.Number(label="Upscaler Increase Size", value=1.5)
|
47 |
+
hires_steps = gr.Number(label="Hires Steps", value=25)
|
48 |
+
|
49 |
+
with gr.Row():
|
50 |
+
generate_button = gr.Button("Generate")
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
output_image = gr.Image(label="Generated Image")
|
54 |
+
|
55 |
+
# Link the button to the generation function
|
56 |
+
generate_button.click(
|
57 |
+
generate_image,
|
58 |
+
inputs=[moelpah, prompt, num_steps, guidance_scale, sampler, img_width, img_height, upscaler_model_path, upscaler_increases_size, hires_steps],
|
59 |
+
outputs=[output_image]
|
60 |
+
)
|
61 |
+
|
62 |
+
# Launch the app
|
63 |
+
demo.launch()
|