Update app.py
#3
by
mygyasir
- opened
app.py
CHANGED
@@ -1,74 +1,12 @@
|
|
1 |
-
import
|
2 |
-
import subprocess
|
3 |
-
from pathlib import Path
|
4 |
-
|
5 |
-
import gradio as gr
|
6 |
import torch
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
with gr.Blocks(theme='nota-ai/theme') as demo:
|
16 |
-
gr.Markdown(Path('docs/header.md').read_text())
|
17 |
-
gr.Markdown(Path('docs/description.md').read_text())
|
18 |
-
with gr.Row():
|
19 |
-
with gr.Column(variant='panel', scale=30):
|
20 |
-
|
21 |
-
text = gr.Textbox(label="Input Prompt", max_lines=5, placeholder="Enter your prompt")
|
22 |
-
|
23 |
-
with gr.Row().style(equal_height=True):
|
24 |
-
generate_original_button = gr.Button(value="Generate with Original Model", variant="primary")
|
25 |
-
generate_compressed_button = gr.Button(value="Generate with Compressed Model", variant="primary")
|
26 |
-
|
27 |
-
with gr.Accordion("Advanced Settings", open=False):
|
28 |
-
negative = gr.Textbox(label=f'Negative Prompt', placeholder=f'Enter aspects to remove (e.g., {"low quality"})')
|
29 |
-
with gr.Row():
|
30 |
-
guidance_scale = gr.Slider(label="Guidance Scale", value=7.5, minimum=4, maximum=11, step=0.5)
|
31 |
-
steps = gr.Slider(label="Denoising Steps", value=25, minimum=10, maximum=75, step=5)
|
32 |
-
seed = gr.Slider(0, 999999, label='Random Seed', value=1234, step=1)
|
33 |
-
|
34 |
-
with gr.Tab("Example Prompts"):
|
35 |
-
examples = gr.Examples(examples=example_list, inputs=[text])
|
36 |
-
|
37 |
-
with gr.Column(variant='panel',scale=35):
|
38 |
-
# Define original model output components
|
39 |
-
gr.Markdown('<h2 align="center">Original Stable Diffusion 1.4</h2>')
|
40 |
-
original_model_output = gr.Image(label="Original Model")
|
41 |
-
with gr.Row().style(equal_height=True):
|
42 |
-
with gr.Column():
|
43 |
-
original_model_test_time = gr.Textbox(value="", label="Inference Time (sec)")
|
44 |
-
original_model_params = gr.Textbox(value=servicer.get_sdm_params(servicer.pipe_original), label="# Parameters")
|
45 |
-
original_model_error = gr.Markdown()
|
46 |
-
|
47 |
-
|
48 |
-
with gr.Column(variant='panel',scale=35):
|
49 |
-
# Define compressed model output components
|
50 |
-
gr.Markdown('<h2 align="center">Compressed Stable Diffusion (Ours)</h2>')
|
51 |
-
compressed_model_output = gr.Image(label="Compressed Model")
|
52 |
-
with gr.Row().style(equal_height=True):
|
53 |
-
with gr.Column():
|
54 |
-
compressed_model_test_time = gr.Textbox(value="", label="Inference Time (sec)")
|
55 |
-
compressed_model_params = gr.Textbox(value=servicer.get_sdm_params(servicer.pipe_compressed), label="# Parameters")
|
56 |
-
compressed_model_error = gr.Markdown()
|
57 |
-
|
58 |
-
inputs = [text, negative, guidance_scale, steps, seed]
|
59 |
-
|
60 |
-
# Click the generate button for original model
|
61 |
-
original_model_outputs = [original_model_output, original_model_error, original_model_test_time]
|
62 |
-
text.submit(servicer.infer_original_model, inputs=inputs, outputs=original_model_outputs)
|
63 |
-
generate_original_button.click(servicer.infer_original_model, inputs=inputs, outputs=original_model_outputs)
|
64 |
-
|
65 |
-
# Click the generate button for compressed model
|
66 |
-
compressed_model_outputs = [compressed_model_output, compressed_model_error, compressed_model_test_time]
|
67 |
-
text.submit(servicer.infer_compressed_model, inputs=inputs, outputs=compressed_model_outputs)
|
68 |
-
generate_compressed_button.click(servicer.infer_compressed_model, inputs=inputs, outputs=compressed_model_outputs)
|
69 |
-
|
70 |
-
gr.Markdown(Path('docs/footer.md').read_text())
|
71 |
-
|
72 |
-
demo.queue(concurrency_count=1)
|
73 |
-
# demo.launch()
|
74 |
-
demo.launch()
|
|
|
1 |
+
from diffusers import DiffusionPipeline
|
|
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
4 |
+
pipe.to("cuda:0")
|
5 |
|
6 |
+
import gradio as gr
|
7 |
+
def gi(prompt):
|
8 |
+
image = pipe(prompt+" hyper real image ,ultra β detailed ,hyper β realistic,8K,photo - hyper realistic, hyper detail β Image",negative_prompt="mutated Image,bad anatomy,deformed Image,extra finger,mutated face,deformed pupils, deformed iris,mutated hands and fingers,deformed hand and fingers ,deformed eye,extra fingers ,less fingers,unrealistic Image,Low Quality,Bad Quality,deformed objects,unrealistic objects,blurry,mutated body,deformed body,deformed leg,mutated leg,deformed foot,mutated foot,deformed shoes,deformed buildings,deformed enviroment,deformed things,bad look,deformed chicks,deformed animals,bad quality,deformed dress").images[0]
|
9 |
+
return image
|
10 |
+
input_box = gr.components.Textbox(placeholder="Enter your text and generate Image in less than a minute!!...")
|
11 |
+
iface = gr.Interface(fn=gi,inputs=input_box,outputs="image",title="Stable Diffusion AI Image Generator")
|
12 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|