Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
| 6 |
import os
|
| 7 |
import spaces
|
| 8 |
|
| 9 |
-
|
| 10 |
if torch.cuda.is_available():
|
| 11 |
device = "cuda"
|
| 12 |
print("Using GPU")
|
|
@@ -14,8 +14,10 @@ else:
|
|
| 14 |
device = "cpu"
|
| 15 |
print("Using CPU")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
|
@@ -27,6 +29,7 @@ pipe.to(device)
|
|
| 27 |
# Enable memory optimizations
|
| 28 |
pipe.enable_attention_slicing()
|
| 29 |
|
|
|
|
| 30 |
# Define the image generation function
|
| 31 |
@spaces.GPU(duration=180)
|
| 32 |
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
|
|
@@ -35,6 +38,7 @@ def generate_image(prompt, num_inference_steps, height, width, guidance_scale, s
|
|
| 35 |
|
| 36 |
generator = torch.Generator().manual_seed(seed)
|
| 37 |
|
|
|
|
| 38 |
with torch.inference_mode():
|
| 39 |
output = pipe(
|
| 40 |
prompt=prompt,
|
|
@@ -48,34 +52,36 @@ def generate_image(prompt, num_inference_steps, height, width, guidance_scale, s
|
|
| 48 |
|
| 49 |
return output
|
| 50 |
|
|
|
|
|
|
|
| 51 |
# Create the Gradio interface
|
|
|
|
| 52 |
examples = [
|
| 53 |
["A cat holding a sign that says hello world"],
|
| 54 |
["a tiny astronaut hatching from an egg on the moon"],
|
| 55 |
-
["An
|
| 56 |
]
|
| 57 |
|
| 58 |
css = '''
|
| 59 |
.gradio-container{max-width: 1000px !important}
|
| 60 |
h1{text-align:center}
|
| 61 |
'''
|
| 62 |
-
|
| 63 |
with gr.Blocks(css=css) as demo:
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Column():
|
| 66 |
gr.HTML(
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
gr.HTML(
|
| 74 |
"""
|
| 75 |
-
|
| 76 |
-
|
| 77 |
"""
|
| 78 |
-
|
| 79 |
with gr.Group():
|
| 80 |
with gr.Column():
|
| 81 |
prompt = gr.Textbox(label="Prompt", info="Describe the image you want", placeholder="A cat...")
|
|
@@ -90,7 +96,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 90 |
height = gr.Slider(label="Height", info="Height of the Image", minimum=256, maximum=1024, step=32, value=1024)
|
| 91 |
with gr.Row():
|
| 92 |
seed = gr.Slider(value=42, minimum=0, maximum=MAX_SEED, step=1, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
|
| 93 |
-
num_images_per_prompt = gr.Slider(label="Images Per Prompt", info="Number of Images to generate with the settings",
|
| 94 |
|
| 95 |
gr.Examples(
|
| 96 |
examples=examples,
|
|
@@ -110,4 +116,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 110 |
outputs=[result],
|
| 111 |
)
|
| 112 |
|
| 113 |
-
demo.queue().launch(share=False)
|
|
|
|
| 6 |
import os
|
| 7 |
import spaces
|
| 8 |
|
| 9 |
+
|
| 10 |
if torch.cuda.is_available():
|
| 11 |
device = "cuda"
|
| 12 |
print("Using GPU")
|
|
|
|
| 14 |
device = "cpu"
|
| 15 |
print("Using CPU")
|
| 16 |
|
| 17 |
+
|
| 18 |
+
# login hf token
|
| 19 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 20 |
+
|
| 21 |
|
| 22 |
MAX_SEED = np.iinfo(np.int32).max
|
| 23 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
|
|
|
| 29 |
# Enable memory optimizations
|
| 30 |
pipe.enable_attention_slicing()
|
| 31 |
|
| 32 |
+
|
| 33 |
# Define the image generation function
|
| 34 |
@spaces.GPU(duration=180)
|
| 35 |
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 38 |
|
| 39 |
generator = torch.Generator().manual_seed(seed)
|
| 40 |
|
| 41 |
+
|
| 42 |
with torch.inference_mode():
|
| 43 |
output = pipe(
|
| 44 |
prompt=prompt,
|
|
|
|
| 52 |
|
| 53 |
return output
|
| 54 |
|
| 55 |
+
|
| 56 |
+
|
| 57 |
# Create the Gradio interface
|
| 58 |
+
|
| 59 |
examples = [
|
| 60 |
["A cat holding a sign that says hello world"],
|
| 61 |
["a tiny astronaut hatching from an egg on the moon"],
|
| 62 |
+
["An astrounat on mars in a futuristic cyborg suit."],
|
| 63 |
]
|
| 64 |
|
| 65 |
css = '''
|
| 66 |
.gradio-container{max-width: 1000px !important}
|
| 67 |
h1{text-align:center}
|
| 68 |
'''
|
|
|
|
| 69 |
with gr.Blocks(css=css) as demo:
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
| 72 |
gr.HTML(
|
| 73 |
+
"""
|
| 74 |
+
<h1 style='text-align: center'>
|
| 75 |
+
FLUX.1-dev
|
| 76 |
+
</h1>
|
| 77 |
+
"""
|
| 78 |
+
)
|
| 79 |
gr.HTML(
|
| 80 |
"""
|
| 81 |
+
Made by <a href='https://linktr.ee/Nick088' target='_blank'>Nick088</a>
|
| 82 |
+
<br> <a href="https://discord.gg/osai"> <img src="https://img.shields.io/discord/1198701940511617164?color=%23738ADB&label=Discord&style=for-the-badge" alt="Discord"> </a>
|
| 83 |
"""
|
| 84 |
+
)
|
| 85 |
with gr.Group():
|
| 86 |
with gr.Column():
|
| 87 |
prompt = gr.Textbox(label="Prompt", info="Describe the image you want", placeholder="A cat...")
|
|
|
|
| 96 |
height = gr.Slider(label="Height", info="Height of the Image", minimum=256, maximum=1024, step=32, value=1024)
|
| 97 |
with gr.Row():
|
| 98 |
seed = gr.Slider(value=42, minimum=0, maximum=MAX_SEED, step=1, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
|
| 99 |
+
num_images_per_prompt = gr.Slider(label="Images Per Prompt", info="Number of Images to generate with the settings",minimum=1, maximum=4, step=1, value=2)
|
| 100 |
|
| 101 |
gr.Examples(
|
| 102 |
examples=examples,
|
|
|
|
| 116 |
outputs=[result],
|
| 117 |
)
|
| 118 |
|
| 119 |
+
demo.queue().launch(share=False)
|