Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import numpy as np | |
| import random | |
| #import spaces #[uncomment to use ZeroGPU] | |
| from pipeline import TextToImagePipeline | |
| import torch | |
| device ="cpu" | |
| torch_dtype = torch.float32 | |
| pipe = TextToImagePipeline(device=device) | |
| MAX_SEED = np.iinfo(np.int32).max | |
| MAX_IMAGE_SIZE = 1024 | |
| #@spaces.GPU #[uncomment to use ZeroGPU] | |
| def infer(prompt, num_inference_steps, amt, progress=gr.Progress(track_tqdm=True)): | |
| image = pipe( | |
| prompt, num_inference_steps, amt | |
| ) | |
| return image | |
| examples = [ | |
| "An airplane is getting ready to land at the airport", | |
| ] | |
| css=""" | |
| #col-container { | |
| margin: 0 auto; | |
| max-width: 640px; | |
| } | |
| """ | |
| with gr.Blocks(css=css) as demo: | |
| with gr.Column(elem_id="col-container"): | |
| gr.Markdown(f""" | |
| # Text-to-Image, made by JBlitzar | |
| """) | |
| with gr.Row(): | |
| prompt = gr.Text( | |
| label="Prompt", | |
| show_label=False, | |
| max_lines=1, | |
| placeholder="Enter your prompt", | |
| container=False, | |
| ) | |
| run_button = gr.Button("Run", scale=0) | |
| result = gr.Image(label="Result", show_label=False) | |
| with gr.Accordion("Advanced Settings", open=False): | |
| amt = gr.Slider( | |
| label="Amount", | |
| minimum=1, | |
| maximum=8, | |
| step=1, | |
| value=8, | |
| ) | |
| steps = gr.Slider( | |
| label="Num inference steps", | |
| minimum=10, | |
| maximum=1000, | |
| step=1, | |
| value=1000, | |
| ) | |
| gr.Examples( | |
| examples = examples, | |
| inputs = [prompt] | |
| ) | |
| gr.on( | |
| triggers=[run_button.click, prompt.submit], | |
| fn = infer, | |
| inputs = [prompt, steps,amt], | |
| outputs = [result] | |
| ) | |
| demo.queue().launch() |