Nick088 commited on
Commit
6c1f991
1 Parent(s): ca8aae4

Upload 3 files

Browse files
Files changed (3) hide show
  1. LICENSE.md +36 -0
  2. app.py +119 -0
  3. requirements.txt +7 -0
LICENSE.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Nick088's Non-Commercial License (NNC)
2
+
3
+ ## 1. Definitions
4
+
5
+ - "Software" refers to the content present within this repository including code, text, graphics, sounds, images, and other files.
6
+ - "You" refers to the individual or entity that wishes to use the Software.
7
+ - "Nick088" refers to the original creator of the Software.
8
+ - "Fork" refers to the action of creating a personal copy of another user's repository.
9
+
10
+ ## 2. Grant of Rights
11
+
12
+ Subject to the terms of this license, Nick088 hereby grants You a worldwide, royalty-free, non-exclusive, perpetual license to use the Software for personal and non-commercial purposes. This includes the rights to use, copy, modify, merge, publish, and distribute the Software for non-commercial purposes.
13
+
14
+ ## 3. Redistribution
15
+
16
+ You may not distribute or sell the Software, or any derivative works based on the Software, unless you have been specifically granted permission by Nick088. Any permitted redistribution must also be under the terms of this license. Unauthorized distribution is strictly prohibited and will result in the termination of this license.
17
+
18
+ ## 4. Commercial Use
19
+
20
+ The use of the Software for commercial purposes, including any form of paid software support and , is strictly forbidden without the explicit written approval of Nick088. This applies to both profit-driven businesses and non-profit organizations that handle monetary transactions.
21
+
22
+ Nick088 may agree to a predetermined or subsequently decided percentage of the profits. Nick088 maintains an upper hand in all such negotiations and reserves any rights, including the right to terminate the contract at any time.
23
+
24
+ Any unauthorized commercial use is strictly prohibited and will result to an immediate termination of this license. In the event of a breach of these terms, Nick088 reserves the right to pursue legal remedies. This may result in litigation, and the offending party may be held liable for any damages incurred. Please be aware that non-compliance with these terms is a serious matter and could have significant legal consequences.
25
+
26
+ ## 5. Forking & Personal Use
27
+
28
+ You are free to fork and modify the Software for your own personal use. You may not distribute, or create derivative works from your modifications unless granted permission by Nick088. All modifications must also be under the terms of this license.
29
+
30
+ ## 6. Liability
31
+
32
+ Nick088 provides the Software "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall Nick088 be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Software or the use or other dealings in the Software. You agree to use the Software at your own risk.
33
+
34
+ ## 7. Governing Law
35
+
36
+ This license is governed by the laws of the jurisdiction in which Nick088 resides. Any disputes related to this license will be resolved in the courts of that jurisdiction.
app.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import FluxPipeline
3
+ import gradio as gr
4
+ import random
5
+ 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")
13
+ else:
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"
24
+
25
+ # Initialize the pipeline and download the model
26
+ pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
27
+ pipe.to(device)
28
+
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)):
36
+ if seed == 0:
37
+ seed = random.randint(1, MAX_SEED)
38
+
39
+ generator = torch.Generator().manual_seed(seed)
40
+
41
+
42
+ with torch.inference_mode():
43
+ output = pipe(
44
+ prompt=prompt,
45
+ num_inference_steps=num_inference_steps,
46
+ height=height,
47
+ width=width,
48
+ guidance_scale=guidance_scale,
49
+ generator=generator,
50
+ num_images_per_prompt=num_images_per_prompt
51
+ ).images
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...")
88
+ run_button = gr.Button("Run")
89
+ result = gr.Gallery(label="Generated AI Images", elem_id="gallery")
90
+ with gr.Accordion("Advanced options", open=False):
91
+ with gr.Row():
92
+ num_inference_steps = gr.Slider(label="Number of Inference Steps", info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference", minimum=1, maximum=50, value=25, step=1)
93
+ guidance_scale = gr.Slider(label="Guidance Scale", info="Controls how much the image generation process follows the text prompt. Higher values make the image stick more closely to the input text.", minimum=0.0, maximum=7.0, value=3.5, step=0.1)
94
+ with gr.Row():
95
+ width = gr.Slider(label="Width", info="Width of the Image", minimum=256, maximum=1024, step=32, value=1024)
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,
103
+ fn=generate_image,
104
+ inputs=[prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt],
105
+ outputs=[result],
106
+ cache_examples=CACHE_EXAMPLES
107
+ )
108
+
109
+ gr.on(
110
+ triggers=[
111
+ prompt.submit,
112
+ run_button.click,
113
+ ],
114
+ fn=generate_image,
115
+ inputs=[prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt],
116
+ outputs=[result],
117
+ )
118
+
119
+ demo.queue().launch(share=False)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ git+https://github.com/huggingface/diffusers.git
4
+ accelerate
5
+ sentencepiece
6
+ numpy
7
+ gradio==4.36.1