ginipick commited on
Commit
0369855
·
verified ·
1 Parent(s): 62c3fc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -53
app.py CHANGED
@@ -3,7 +3,7 @@ import spaces
3
  import torch
4
  from diffusers import FluxKontextPipeline
5
  from diffusers.utils import load_image
6
- from PIL import Image, ImageDraw, ImageFont
7
  import os
8
 
9
  # Style dictionary
@@ -88,52 +88,7 @@ thumbnail_mapping = {
88
  pipeline = None
89
  pipeline_loaded = False
90
 
91
- def add_watermark(image):
92
- """Add watermark to the generated image"""
93
- # Create a copy of the image
94
- watermarked = image.copy()
95
-
96
- # Create drawing context
97
- draw = ImageDraw.Draw(watermarked)
98
-
99
- # Define watermark text
100
- watermark_text = "ginigen.com"
101
-
102
- # Try to use a default font, fallback to basic if not available
103
- try:
104
- # Try to use a smaller font size
105
- font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 16)
106
- except:
107
- try:
108
- font = ImageFont.truetype("arial.ttf", 16)
109
- except:
110
- # Use default font if no TrueType fonts are available
111
- font = ImageFont.load_default()
112
-
113
- # Get text size
114
- bbox = draw.textbbox((0, 0), watermark_text, font=font)
115
- text_width = bbox[2] - bbox[0]
116
- text_height = bbox[3] - bbox[1]
117
-
118
- # Calculate position (bottom right with padding)
119
- padding = 10
120
- box_padding = 5
121
- x = image.width - text_width - padding - (box_padding * 2)
122
- y = image.height - text_height - padding - (box_padding * 2)
123
-
124
- # Draw semi-transparent box background
125
- box_coords = [
126
- x - box_padding,
127
- y - box_padding,
128
- x + text_width + box_padding,
129
- y + text_height + box_padding
130
- ]
131
- draw.rectangle(box_coords, fill=(255, 255, 255, 200))
132
-
133
- # Draw text
134
- draw.text((x, y), watermark_text, font=font, fill=(100, 100, 100, 255))
135
-
136
- return watermarked
137
  global pipeline, pipeline_loaded
138
  if pipeline is None:
139
  print("Loading FLUX.1-Kontext-dev model...")
@@ -227,11 +182,7 @@ def style_transfer(input_image, style_name, prompt_suffix, num_inference_steps,
227
  # Clear GPU memory
228
  torch.cuda.empty_cache()
229
 
230
- # Add watermark to the generated image
231
- result_image = result.images[0]
232
- watermarked_image = add_watermark(result_image)
233
-
234
- return watermarked_image
235
 
236
  except Exception as e:
237
  print(f"Error: {str(e)}")
@@ -264,7 +215,7 @@ def create_thumbnail_grid():
264
 
265
  # Create Gradio interface
266
  with gr.Blocks(title="Flux Kontext Style LoRA", theme=gr.themes.Soft()) as demo:
267
- gr.Markdown("# 🎨 Flux Kontext Style LoRA")
268
 
269
  # Thumbnail Grid Section
270
  with gr.Row():
 
3
  import torch
4
  from diffusers import FluxKontextPipeline
5
  from diffusers.utils import load_image
6
+ from PIL import Image
7
  import os
8
 
9
  # Style dictionary
 
88
  pipeline = None
89
  pipeline_loaded = False
90
 
91
+ def load_pipeline():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  global pipeline, pipeline_loaded
93
  if pipeline is None:
94
  print("Loading FLUX.1-Kontext-dev model...")
 
182
  # Clear GPU memory
183
  torch.cuda.empty_cache()
184
 
185
+ return result.images[0]
 
 
 
 
186
 
187
  except Exception as e:
188
  print(f"Error: {str(e)}")
 
215
 
216
  # Create Gradio interface
217
  with gr.Blocks(title="Flux Kontext Style LoRA", theme=gr.themes.Soft()) as demo:
218
+ gr.Markdown("# 🎨 Flux Styler : Flux Kontext Style LoRA")
219
 
220
  # Thumbnail Grid Section
221
  with gr.Row():