idlebg commited on
Commit
d6a1347
β€’
1 Parent(s): 1b723a3

add legal text watermark

Browse files
Files changed (1) hide show
  1. app.py +50 -20
app.py CHANGED
@@ -31,6 +31,26 @@ pipe1.enable_xformers_memory_efficient_attention()
31
  pipe2 = pipe2.to(device)
32
  pipe2.enable_xformers_memory_efficient_attention()
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def save_image_to_hf_space(image_np, image_name):
35
  # Name of your Hugging Face repo
36
  repo_name = "FFusion/FF2"
@@ -61,20 +81,24 @@ def save_image_to_hf_space(image_np, image_name):
61
 
62
 
63
 
64
- def genie(prompt, negative_prompt, prompt_2, negative_prompt_2, scale, guidance_scale, aesthetic_score, negative_aesthetic_score, steps, seed):
65
  torch.cuda.empty_cache()
66
  generator = torch.Generator(device=device).manual_seed(seed)
67
- int_images = pipe1(prompt=prompt, prompt_2=prompt_2, negative_prompt=negative_prompt, negative_prompt_2=negative_prompt_2, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator).images
68
  torch.cuda.empty_cache()
69
  refined_images = pipe2(prompt=prompt, prompt_2=prompt_2, image=int_images, guidance_scale=guidance_scale, aesthetic_score=aesthetic_score, negative_aesthetic_score=negative_aesthetic_score).images
70
  int_image_np = np.array(int_images[0])
71
  refined_image_np = np.array(refined_images[0])
72
 
 
 
 
 
73
  # Save the generated images to Hugging Face Spaces
74
- save_image_to_hf_space(int_image_np, "int_image")
75
- save_image_to_hf_space(refined_image_np, "refined_image")
76
 
77
- return int_image_np, refined_image_np
78
 
79
  article = f"""
80
  <div style="text-align: center;">
@@ -84,9 +108,11 @@ article = f"""
84
  <h2>Citation</h2>
85
  <p>Please note that the demo is intended solely for academic and research purposes. This demo features the FFusionXL-BASE model developed by FFusion.AI, a division of Source Code Bulgaria Ltd.</p>
86
  <h2>Acknowledgement of Original Work and Modifications</h2>
87
- <p>This Software is based on the Stable Diffusion XL Base 1.0 model developed by Stability AI Ltd. FFusion AI and Source Code Bulgaria Ltd. have made modifications and enhancements to the original Software for the creation of the FFusionXL-BASE model...</p>
88
- <h2>Warning and Compliance</h2>
89
- <p><span style="color: red; font-weight: bold;">All images and content generated through this demo are logged in a Hugging Face repository, and we actively monitor for violations of these terms.</span> Any use of the demo for generating inappropriate or unlawful content is strictly prohibited...</p>
 
 
90
  <h2>License</h2>
91
  <p><a href="https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9/blob/main/LICENSE.md">SDXL 0.9 Research License</a></p>
92
  <p><a href="https://huggingface.co/FFusion/FFusionXL-09-SDXL/blob/main/LICENSE.md">FFXL 0.9 Research License</a></p>
@@ -106,17 +132,20 @@ article = f"""
106
  """
107
 
108
  # Create the Gradio interface
109
- gr.Interface(fn=genie,
110
- inputs=[gr.Textbox(label='Describe your FFusion idea. 77 Token Limit.', lines=2),
111
- gr.Textbox(label='Things the AI should not create (negative prompt)', lines=2),
112
- gr.Textbox(label='Additional prompt for text-encoder 2 (optional)', lines=2, optional=True),
113
- gr.Textbox(label='Negative prompt for text-encoder 2 (optional)', lines=2, optional=True),
114
- gr.Slider(1, 15, 10, label='Scale'),
115
- gr.Slider(1, 10, 5, label='Guidance Scale'),
116
- gr.Slider(1, 10, 6, label='Aesthetic Score'),
117
- gr.Slider(1, 10, 2.5, label='Negative Aesthetic Score'),
118
- gr.Slider(25, maximum=5, value=50, step=1, label='Steps'),
119
- gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True, label='Seed')],
 
 
 
120
  outputs=[gc.Image(type='numpy', label="FFusionXL Base Image"), gc.Image(type='numpy', label="Refined Image")],
121
  title="FFusionXL Base - Generate and Refine",
122
  description='<div style="display: flex; flex-wrap: wrap; gap: 2px; justify-content: center;"><a href="https://huggingface.co/FFusion/FFusionXL-BASE" target="_new" rel="ugc"><img src="https://img.shields.io/badge/FFusionXL--BASE--SDXL-Model-pink" alt="FFusionXL-BASE-SDXL"></a> <a href="https://huggingface.co/FFusion/FFusionXL-09-SDXL/blob/main/LICENSE.md" target="_new" rel="ugc"><img src="https://img.shields.io/badge/License-FFXL%20Research%20License-blue"></a></div>',
@@ -129,5 +158,6 @@ gr.Interface(fn=genie,
129
  max-width: 50%;
130
  display: inline-block;
131
  }
132
- """
 
133
  ).launch(debug=True, max_threads=10)
 
31
  pipe2 = pipe2.to(device)
32
  pipe2.enable_xformers_memory_efficient_attention()
33
 
34
+
35
+
36
+
37
+
38
+ def add_watermark(image_np):
39
+ img = Image.fromarray(image_np.astype('uint8'))
40
+ draw = ImageDraw.Draw(img)
41
+ watermark_text_line1 = "WARNING: This image is generated for Research & Demonstration Purposes Only."
42
+ watermark_text_line2 = "Any misuse or inappropriate use and may be subject to legal action."
43
+ font = ImageFont.truetype("arial.ttf", size=12)
44
+ position_line1 = (10, img.height - 80)
45
+ position_line2 = (10, img.height - 60) # Adjust this value based on the font size and desired spacing
46
+ color_line1 = "white"
47
+ color_line2 = "black"
48
+ draw.text(position_line1, watermark_text_line1, font=font, fill=color_line1)
49
+ draw.text(position_line2, watermark_text_line2, font=font, fill=color_line2)
50
+ return np.array(img)
51
+
52
+
53
+
54
  def save_image_to_hf_space(image_np, image_name):
55
  # Name of your Hugging Face repo
56
  repo_name = "FFusion/FF2"
 
81
 
82
 
83
 
84
+ def genie(prompt, negative_prompt, prompt_2, negative_prompt_2, scale, guidance_scale, height, width, aesthetic_score, negative_aesthetic_score, steps, seed):
85
  torch.cuda.empty_cache()
86
  generator = torch.Generator(device=device).manual_seed(seed)
87
+ int_images = pipe1(prompt=prompt, prompt_2=prompt_2, negative_prompt=negative_prompt, negative_prompt_2=negative_prompt_2, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator).images
88
  torch.cuda.empty_cache()
89
  refined_images = pipe2(prompt=prompt, prompt_2=prompt_2, image=int_images, guidance_scale=guidance_scale, aesthetic_score=aesthetic_score, negative_aesthetic_score=negative_aesthetic_score).images
90
  int_image_np = np.array(int_images[0])
91
  refined_image_np = np.array(refined_images[0])
92
 
93
+ # Add watermark to the images
94
+ int_image_np_with_watermark = add_watermark(int_image_np)
95
+ refined_image_np_with_watermark = add_watermark(refined_image_np)
96
+
97
  # Save the generated images to Hugging Face Spaces
98
+ save_image_to_hf_space(int_image_np_with_watermark, "int_image")
99
+ save_image_to_hf_space(refined_image_np_with_watermark, "refined_image")
100
 
101
+ return int_image_np_with_watermark, refined_image_np_with_watermark
102
 
103
  article = f"""
104
  <div style="text-align: center;">
 
108
  <h2>Citation</h2>
109
  <p>Please note that the demo is intended solely for academic and research purposes. This demo features the FFusionXL-BASE model developed by FFusion.AI, a division of Source Code Bulgaria Ltd.</p>
110
  <h2>Acknowledgement of Original Work and Modifications</h2>
111
+ <p>This Software is based on the Stable Diffusion XL Base 1.0 model developed by Stability AI Ltd. FFusion AI and Source Code Bulgaria Ltd. have made modifications and enhancements to the original Software for the creation of the FFusionXL-BASE model. While FFusion AI and Source Code Bulgaria Ltd. maintain the rights to their modifications and enhancements, all rights to the original Software and associated intellectual property remain with Stability AI Ltd. Use of the FFusionXL-BASE model is subject to the terms of this License, as well as any terms and conditions set forth by Stability AI Ltd. for the use of the original Software.</p>
112
+ <p>Attribution: SDXL 0.9 is licensed under the SDXL Research License, Copyright (c) Stability AI Ltd. All Rights Reserved.</p>
113
+ <h2>Warning and Compliance</h2>
114
+ <p>Any use of the demo for generating inappropriate or unlawful content is strictly prohibited, and any misuse will not be tolerated. Individuals found to be generating content that is in violation of these terms or any applicable laws will be dealt with accordingly in accordance with legal regulations. The responsibility for any misuse or inappropriate use of the demo lies solely with the users who generated such content, and this demo, nor its affiliates, shall be held liable for any such use.</p>
115
+ <p><span style="color: red; font-weight: bold;">All images and content generated through this demo are logged in a Hugging Face repository, and we actively monitor for violations of these terms.</span> </p>
116
  <h2>License</h2>
117
  <p><a href="https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9/blob/main/LICENSE.md">SDXL 0.9 Research License</a></p>
118
  <p><a href="https://huggingface.co/FFusion/FFusionXL-09-SDXL/blob/main/LICENSE.md">FFXL 0.9 Research License</a></p>
 
132
  """
133
 
134
  # Create the Gradio interface
135
+ gr.Interface(fn=genie, inputs=[
136
+ gr.Textbox(label='🎨 Main Prompt', placeholder='Describe the Desired Image (77 Token Limit)', lines=2),
137
+ gr.Textbox(label='❌ Negative Prompt', placeholder='Specify Unwanted Elements', lines=2),
138
+ gr.Textbox(label='πŸ“ Secondary Prompt for Text Encoder 2', placeholder='The prompt for tokenizer_2 and text_encoder_2 (Optional)', lines=1),
139
+ gr.Textbox(label='❌ Negative Prompt for Text Encoder 2', placeholder='Negative guidance for text_encoder_2 (Optional)', lines=1),
140
+ gr.Slider(3, 25, 10, label='🌊 DiFFusion Scale: Influence of Main Features'),
141
+ gr.Slider(1, 10, 5, label='🧭 Guidance Scale: Intensity of Guidance'),
142
+ #gr.Slider(640, 1024, 1024, step=128, label='πŸ“ Height'),
143
+ #gr.Slider(640, 1280, 1024, step=128, label='πŸ“ Width'),
144
+ gr.Slider(1, 10, 6, label='🎨 Aesthetic Score: Preference for Visual Appeal'),
145
+ gr.Slider(1, 10, 2.5, label='🚫 Negative Aesthetic Score: Avoidance of Unwanted Aesthetics'),
146
+ gr.Slider(10, maximum=80, value=50, step=1, label='πŸ’Ž Number of Diffusion Steps'),
147
+ gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True, label='🎲 Seed')],
148
+
149
  outputs=[gc.Image(type='numpy', label="FFusionXL Base Image"), gc.Image(type='numpy', label="Refined Image")],
150
  title="FFusionXL Base - Generate and Refine",
151
  description='<div style="display: flex; flex-wrap: wrap; gap: 2px; justify-content: center;"><a href="https://huggingface.co/FFusion/FFusionXL-BASE" target="_new" rel="ugc"><img src="https://img.shields.io/badge/FFusionXL--BASE--SDXL-Model-pink" alt="FFusionXL-BASE-SDXL"></a> <a href="https://huggingface.co/FFusion/FFusionXL-09-SDXL/blob/main/LICENSE.md" target="_new" rel="ugc"><img src="https://img.shields.io/badge/License-FFXL%20Research%20License-blue"></a></div>',
 
158
  max-width: 50%;
159
  display: inline-block;
160
  }
161
+ """,
162
+ allow_flagging='never'
163
  ).launch(debug=True, max_threads=10)