81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
#!/usr/bin/env python
|
|
|
|
import pathlib
|
|
import shlex
|
|
import subprocess
|
|
import gradio as gr
|
|
from model import Model
|
|
from settings import CACHE_EXAMPLES, MAX_SEED
|
|
from utils import randomize_seed_fn
|
|
from gradio.themes.utils import sizes
|
|
|
|
|
|
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
|
block_label_text_color = '#4D63FF',
|
|
block_title_text_color = '#4D63FF',
|
|
button_primary_text_color = '#4D63FF',
|
|
button_primary_background_fill='#FFFFFF',
|
|
button_primary_border_color='#4D63FF',
|
|
button_primary_background_fill_hover='#EDEFFF',
|
|
)
|
|
|
|
|
|
def create_demo(model: Model) -> gr.Blocks:
|
|
examples = ['corgi.png']
|
|
|
|
def process_example_fn(image_path: str) -> str:
|
|
return model.run_image(image_path)
|
|
|
|
with gr.Blocks(theme=theme) as demo:
|
|
with gr.Box():
|
|
image = gr.Image(label='输入图片',
|
|
show_label=False,
|
|
type='filepath')
|
|
run_button = gr.Button('运行')
|
|
result = gr.Model3D(label='结果', show_label=False)
|
|
with gr.Accordion('高级选项', open=False):
|
|
seed = gr.Slider(label='Seed',
|
|
minimum=0,
|
|
maximum=MAX_SEED,
|
|
step=1,
|
|
value=0)
|
|
randomize_seed = gr.Checkbox(label='Randomize seed',
|
|
value=True)
|
|
guidance_scale = gr.Slider(label='Guidance scale',
|
|
minimum=1,
|
|
maximum=20,
|
|
step=0.1,
|
|
value=3.0)
|
|
num_inference_steps = gr.Slider(
|
|
label='Number of inference steps',
|
|
minimum=1,
|
|
maximum=100,
|
|
step=1,
|
|
value=64)
|
|
|
|
gr.Examples(examples=examples,
|
|
inputs=image,
|
|
outputs=result,
|
|
fn=process_example_fn,
|
|
cache_examples=CACHE_EXAMPLES,
|
|
label="例子")
|
|
|
|
inputs = [
|
|
image,
|
|
seed,
|
|
guidance_scale,
|
|
num_inference_steps,
|
|
]
|
|
|
|
run_button.click(
|
|
fn=randomize_seed_fn,
|
|
inputs=[seed, randomize_seed],
|
|
outputs=seed,
|
|
queue=False,
|
|
).then(
|
|
fn=model.run_image,
|
|
inputs=inputs,
|
|
outputs=result,
|
|
)
|
|
return demo
|