import gradio as gr import random model = gr.load("models/Purz/face-projection") def generate_image(text): return model(text) examples = [ ["Humanoid Cat Warrior, Full View"], ["Warhammer Sisterhood"], ["Future Robots war"], ["Fantasy dragon"] ] css = """ #col-container { margin: 0 auto; max-width: 640px; } """ with gr.Blocks(css=css) as interface: with gr.Column(elem_id="col-container"): gr.Markdown("# Text-to-Image Gradio Template") gr.Markdown("Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.") with gr.Row(): prompt = gr.Textbox( label="Type here your imagination:", show_label=False, max_lines=1, placeholder="Type or click an example...", container=False, ) run_button = gr.Button("Generate Image", scale=0, variant="primary") result = gr.Image(label="Generated Image", show_label=False) with gr.Accordion("Advanced Settings", open=False): negative_prompt = gr.Text( label="Negative prompt", max_lines=1, placeholder="Enter a negative prompt", visible=False, ) with gr.Row(): width = gr.Slider( label="Width", minimum=256, maximum=1024, step=32, value=1024 ) height = gr.Slider( label="Height", minimum=256, maximum=1024, step=32, value=1024 ) with gr.Row(): guidance_scale = gr.Slider( label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=0.0 ) num_inference_steps = gr.Slider( label="Number of inference steps", minimum=1, maximum=50, step=1, value=2 ) gr.Examples(examples=examples, inputs=[prompt]) gr.on( triggers=[run_button.click, prompt.submit], fn=generate_image, inputs=[prompt], outputs=[result], ) if __name__ == "__main__": interface.launch()