Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files13 unmodified lines141516171819202122233 unmodified lines272829303132333435363738394041424334 unmodified lines78798081828384858687888990918 unmodified lines1001011021031041051066 unmodified lines1131141151161171181194 unmodified lines12412512612712812913085 unmodified lines21621721821922022122213 unmodified lines"""css = '''.gradio-container{max-width: 560px !important}h1{text-align:center}footer {visibility: hidden}'''3 unmodified lines"Vector illustration of a horse, vector graphic design with flat colors on an brown background in the style of vector art, using simple shapes and graphics with simple details, professionally designed as a tshirt logo ready for print on a white background. --ar 89:82 --v 6.0 --style raw","Man in brown leather jacket posing for camera, in the style of sleek and stylized, clockpunk, subtle shades, exacting precision, ferrania p30 --ar 67:101 --v 5","Commercial photography, giant burger, white lighting, studio light, 8k octane rendering, high resolution photography, insanely detailed, fine details, on white isolated plain, 8k, commercial photography, stock photo, professional color grading, --v 4 --ar 9:16 "]MODEL_ID = os.getenv("MODEL_VAL_PATH") #uses SG161222/RealVisXL_V5.0_Lightning or SG161222/RealVisXL_V4.0_LightningMAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once#Load model outside of functiondevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")pipe = StableDiffusionXLPipeline.from_pretrained(MODEL_ID,34 unmodified linesguidance_scale: float = 3,num_inference_steps: int = 25,randomize_seed: bool = False,use_resolution_binning: bool = True,num_images: int = 4, # Number of images to generateprogress=gr.Progress(track_tqdm=True),):seed = int(randomize_seed_fn(seed, randomize_seed))generator = torch.Generator(device=device).manual_seed(seed)#Optionsoptions = {"prompt": [prompt] * num_images,"negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,8 unmodified linesif use_resolution_binning:options["use_resolution_binning"] = True#Images potential batchesimages = []for i in range(0, num_images, BATCH_SIZE):batch_options = options.copy()6 unmodified linesreturn image_paths, seedwith gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:gr.Markdown(DESCRIPTIONx)with gr.Group():with gr.Row():prompt = gr.Text(4 unmodified linescontainer=False,)run_button = gr.Button("Run", scale=0)result = gr.Gallery(label="Result", columns=2, show_label=False)with gr.Accordion("Advanced options", open=False, visible=True):num_images = gr.Slider(label="Number of Images",85 unmodified lines],outputs=[result, seed],api_name="run",)if __name__ == "__main__":demo.queue(max_size=40).launch(ssr_mode=False)13 unmodified lines1415161718192021222324252627283 unmodified lines32333435363738394041424344454634 unmodified lines81828384858687888990919293948 unmodified lines1031041051061071081096 unmodified lines1161171181191201211224 unmodified lines12712812913013113213385 unmodified lines21922022122222322422513 unmodified lines"""css = '''.gradio-container {max-width: 560px !important;margin: 0 auto !important;}h1 {text-align: center;}footer {visibility: hidden;}'''3 unmodified lines"Vector illustration of a horse, vector graphic design with flat colors on an brown background in the style of vector art, using simple shapes and graphics with simple details, professionally designed as a tshirt logo ready for print on a white background. --ar 89:82 --v 6.0 --style raw","Man in brown leather jacket posing for camera, in the style of sleek and stylized, clockpunk, subtle shades, exacting precision, ferrania p30 --ar 67:101 --v 5","Commercial photography, giant burger, white lighting, studio light, 8k octane rendering, high resolution photography, insanely detailed, fine details, on white isolated plain, 8k, commercial photography, stock photo, professional color grading, --v 4 --ar 9:16 "]MODEL_ID = os.getenv("MODEL_VAL_PATH") # uses SG161222/RealVisXL_V5.0_Lightning or SG161222/RealVisXL_V4.0_LightningMAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once# Load model outside of functiondevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")pipe = StableDiffusionXLPipeline.from_pretrained(MODEL_ID,34 unmodified linesguidance_scale: float = 3,num_inference_steps: int = 25,randomize_seed: bool = False,use_resolution_binning: bool = True,num_images: int = 4, # Number of images to generateprogress=gr.Progress(track_tqdm=True),):seed = int(randomize_seed_fn(seed, randomize_seed))generator = torch.Generator(device=device).manual_seed(seed)# Optionsoptions = {"prompt": [prompt] * num_images,"negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,8 unmodified linesif use_resolution_binning:options["use_resolution_binning"] = True# Images potential batchesimages = []for i in range(0, num_images, BATCH_SIZE):batch_options = options.copy()6 unmodified linesreturn image_paths, seedwith gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:gr.Markdown(DESCRIPTIONx)with gr.Group():with gr.Row():prompt = gr.Text(4 unmodified linescontainer=False,)run_button = gr.Button("Run", scale=0)result = gr.Gallery(label="Result", columns=2, show_label=False)with gr.Accordion("Advanced options", open=False, visible=True):num_images = gr.Slider(label="Number of Images",85 unmodified lines],outputs=[result, seed],api_name="run",)if __name__ == "__main__":demo.queue(max_size=40).launch(ssr_mode=False)
app.py+16-13