Spaces:
Paused
Paused
File size: 4,824 Bytes
c66f90b 1d5f68d 65572dd b3d2790 515dc44 65572dd 515dc44 b3d2790 515dc44 65572dd 19b2372 515dc44 65572dd 515dc44 19b2372 515dc44 65572dd 515dc44 65572dd 19b2372 515dc44 19b2372 65572dd 515dc44 1d5f68d c66f90b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
import gradio as gr
import numpy as np
import random
import spaces
from diffusers import DiffusionPipeline
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model_repo_id = "stabilityai/stable-diffusion-3.5-large"
if torch.cuda.is_available():
torch_dtype = torch.bfloat16
else:
torch_dtype = torch.float32
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
pipe = pipe.to(device)
MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 1024
@spaces.GPU(duration=45)
def infer(
prompt,
negative_prompt="",
seed=42,
randomize_seed=False,
width=768,
height=768,
guidance_scale=4.5,
num_inference_steps=20,
progress=gr.Progress(track_tqdm=True),
):
if randomize_seed:
seed = random.randint(0, MAX_SEED)
generator = torch.Generator().manual_seed(seed)
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
width=width,
height=height,
generator=generator,
).images[0]
return image, seed
examples = [
"A full-body depiction of a futuristic cyberpunk warrior wearing neon armor with intricate details, holding a sleek glowing katana in a ready stance. The character stands confidently with glowing eyes and a dynamic pose that exudes strength and mystery. Isolated on a clean, transparent, or neutral background to emphasize the character's design and details, with subtle reflections and lighting to enhance the neon glow and textures.",
]
# Define the custom theme with input styles
class CustomTheme(gr.themes.Base):
def __init__(self):
super().__init__()
self.primary_hue = "#5271FF"
self.background_fill_primary = "#17181B"
self.background_fill_secondary = "#17181B"
self.background_fill_tertiary = "#17181B"
self.text_color_primary = "#AEB3B8"
self.text_color_secondary = "#AEB3B8"
self.text_color_tertiary = "#AEB3B8"
self.input_background_fill = "#17181B" # Set input background color
self.input_text_color = "#AEB3B8" # Set input text color
# Custom CSS to hide the footer, set fonts, and adjust font weights
css = """
/* Hide the footer */
footer {
visibility: hidden;
height: 0;
margin: 0;
padding: 0;
overflow: hidden;
}
/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Montserrat:wght@500;700&display=swap');
/* Apply fonts to different elements */
body, input, button, textarea, select, .gr-button {
font-family: 'Roboto', sans-serif;
}
/* Make button text normal weight */
.generate-button, .generate-button .gr-button {
font-weight: normal !important;
}
/* Ensure headings use Montserrat */
h1, h2, h3, h4, h5, h6 {
font-family: 'Montserrat', sans-serif;
font-weight: 700;
}
/* Additional styling for sliders and checkboxes if needed */
input[type="range"]::-webkit-slider-thumb {
background: #5271FF;
}
input[type="range"]::-moz-range-thumb {
background: #5271FF;
}
input[type="range"]::-ms-thumb {
background: #5271FF;
}
input[type="checkbox"]:checked {
background-color: #5271FF;
}
/* Make Prompt text bold */
.prompt-text {
font-weight: bold;
}
"""
with gr.Blocks(theme=CustomTheme(), css=css) as demo:
with gr.Column(elem_id="col-container"):
# Make "Prompt" bold using Markdown syntax and assign a class
gr.Markdown("**Prompt**", elem_classes="prompt-text")
with gr.Row():
prompt = gr.Text(
label="Prompt",
show_label=False,
max_lines=1,
placeholder="Enter your prompt",
container=False,
)
run_button = gr.Button(
"Generate",
scale=0,
variant="primary",
elem_classes="generate-button"
)
result = gr.Image(label="Result", show_label=False)
# Removed Advanced Settings block
gr.Examples(
examples=examples,
inputs=[prompt],
outputs=[result],
fn=infer,
cache_examples=True,
cache_mode="lazy"
)
# Use click method for the button and submit for the text field
run_button.click(
fn=infer,
inputs=[prompt], # Only the prompt as input
outputs=[result], # Only result as output
)
prompt.submit(
fn=infer,
inputs=[prompt], # Only the prompt as input
outputs=[result], # Only result as output
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
show_api=False
) |