muhammadsalmanalfaridzi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -38,12 +38,14 @@ def remove_background_bria(input_path):
|
|
38 |
|
39 |
# Fungsi untuk memproses gambar menggunakan prompt
|
40 |
def text_to_image(prompt):
|
|
|
41 |
image = sd_model(prompt).images[0] # Use sd_model instead of pipe
|
42 |
image_path = f"generated_images/{prompt.replace(' ', '_')}.png"
|
43 |
image.save(image_path)
|
44 |
return image, image_path
|
45 |
|
46 |
def text_image_to_image(image, prompt):
|
|
|
47 |
# Convert input image to PIL Image for processing
|
48 |
modified_image = sd_model(prompt, init_image=image, strength=0.75).images[0] # Use sd_model here too
|
49 |
image_path = f"generated_images/{prompt.replace(' ', '_')}_modified.png"
|
@@ -493,8 +495,16 @@ def create_canvas(canvas_size, bg_choice, custom_color):
|
|
493 |
|
494 |
def apply_watermark(canvas, watermark_path):
|
495 |
watermark = Image.open(watermark_path).convert("RGBA")
|
496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
|
|
|
|
498 |
def save_image(canvas, output_folder, filename, output_format):
|
499 |
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|
500 |
output_path = os.path.join(output_folder, f"{os.path.splitext(filename)[0]}.{output_ext}")
|
|
|
38 |
|
39 |
# Fungsi untuk memproses gambar menggunakan prompt
|
40 |
def text_to_image(prompt):
|
41 |
+
os.makedirs("generated_images", exist_ok=True)
|
42 |
image = sd_model(prompt).images[0] # Use sd_model instead of pipe
|
43 |
image_path = f"generated_images/{prompt.replace(' ', '_')}.png"
|
44 |
image.save(image_path)
|
45 |
return image, image_path
|
46 |
|
47 |
def text_image_to_image(image, prompt):
|
48 |
+
os.makedirs("generated_images", exist_ok=True)
|
49 |
# Convert input image to PIL Image for processing
|
50 |
modified_image = sd_model(prompt, init_image=image, strength=0.75).images[0] # Use sd_model here too
|
51 |
image_path = f"generated_images/{prompt.replace(' ', '_')}_modified.png"
|
|
|
495 |
|
496 |
def apply_watermark(canvas, watermark_path):
|
497 |
watermark = Image.open(watermark_path).convert("RGBA")
|
498 |
+
|
499 |
+
# Calculate the position to center the watermark
|
500 |
+
canvas_width, canvas_height = canvas.size
|
501 |
+
watermark_width, watermark_height = watermark.size
|
502 |
+
|
503 |
+
x = (canvas_width - watermark_width) // 2
|
504 |
+
y = (canvas_height - watermark_height) // 2
|
505 |
|
506 |
+
canvas.paste(watermark, (x, y), watermark)
|
507 |
+
|
508 |
def save_image(canvas, output_folder, filename, output_format):
|
509 |
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|
510 |
output_path = os.path.join(output_folder, f"{os.path.splitext(filename)[0]}.{output_ext}")
|