Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ import spaces
|
|
12 |
import numpy as np
|
13 |
import cv2
|
14 |
from pyzxing import BarCodeReader
|
15 |
-
from PIL import ImageOps
|
16 |
from huggingface_hub import hf_hub_download, snapshot_download
|
17 |
from PIL import ImageEnhance
|
18 |
|
@@ -338,6 +338,42 @@ def invert_init_image_display(image):
|
|
338 |
return Image.fromarray(inverted)
|
339 |
return inverted
|
340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
css = """
|
342 |
h1, h2, h3, h4, h5, h6, p, li, ul, ol, a, .centered-image {
|
343 |
text-align: center;
|
@@ -389,12 +425,13 @@ with gr.Blocks(theme='Hev832/Applio', css=css, fill_width=True, fill_height=True
|
|
389 |
)
|
390 |
|
391 |
# Add login form
|
392 |
-
with gr.
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
|
|
398 |
|
399 |
|
400 |
with gr.Tab("QR Code and Prompt Input", visible=False) as app_container:
|
@@ -626,6 +663,17 @@ with gr.Blocks(theme='Hev832/Applio', css=css, fill_width=True, fill_height=True
|
|
626 |
image_selector = gr.Dropdown(label="Select Image to Edit", choices=[], interactive=True, visible=False)
|
627 |
image_to_edit = gr.Image(label="Your Artistic QR Code", show_download_button=True, show_fullscreen_button=True)
|
628 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
629 |
with gr.Row():
|
630 |
brightness = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Brightness")
|
631 |
contrast = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Contrast")
|
@@ -635,8 +683,8 @@ with gr.Blocks(theme='Hev832/Applio', css=css, fill_width=True, fill_height=True
|
|
635 |
|
636 |
with gr.Row():
|
637 |
edited_image = gr.Image(label="Edited QR Code", show_download_button=True, show_fullscreen_button=True, visible=False)
|
638 |
-
scan_button = gr.Button("Verify QR Code Works", size="sm")
|
639 |
-
scan_result = gr.Textbox(label="Validation Result of QR Code", interactive=False)
|
640 |
|
641 |
used_seed = gr.Number(label="Seed Used", interactive=False)
|
642 |
|
|
|
12 |
import numpy as np
|
13 |
import cv2
|
14 |
from pyzxing import BarCodeReader
|
15 |
+
from PIL import ImageOps, ImageEnhance, ImageFilter
|
16 |
from huggingface_hub import hf_hub_download, snapshot_download
|
17 |
from PIL import ImageEnhance
|
18 |
|
|
|
338 |
return Image.fromarray(inverted)
|
339 |
return inverted
|
340 |
|
341 |
+
def adjust_color_balance(image, r, g, b):
|
342 |
+
# Convert image to RGB if it's not already
|
343 |
+
image = image.convert('RGB')
|
344 |
+
|
345 |
+
# Split the image into its RGB channels
|
346 |
+
r_channel, g_channel, b_channel = image.split()
|
347 |
+
|
348 |
+
# Adjust each channel
|
349 |
+
r_channel = r_channel.point(lambda i: i + (i * r))
|
350 |
+
g_channel = g_channel.point(lambda i: i + (i * g))
|
351 |
+
b_channel = b_channel.point(lambda i: i + (i * b))
|
352 |
+
|
353 |
+
# Merge the channels back
|
354 |
+
return Image.merge('RGB', (r_channel, g_channel, b_channel))
|
355 |
+
|
356 |
+
def apply_qr_overlay(image, original_qr, overlay, opacity):
|
357 |
+
if not overlay or original_qr is None:
|
358 |
+
return image
|
359 |
+
|
360 |
+
# Resize original QR to match the generated image
|
361 |
+
original_qr = original_qr.resize(image.size)
|
362 |
+
|
363 |
+
# Create a new image blending the generated image and the QR code
|
364 |
+
return Image.blend(image, original_qr, opacity)
|
365 |
+
|
366 |
+
def apply_edge_enhancement(image, strength):
|
367 |
+
if strength == 0:
|
368 |
+
return image
|
369 |
+
|
370 |
+
# Apply edge enhancement
|
371 |
+
enhanced = image.filter(ImageFilter.EDGE_ENHANCE)
|
372 |
+
|
373 |
+
# Blend the original and enhanced images based on strength
|
374 |
+
return Image.blend(image, enhanced, strength / 5.0)
|
375 |
+
|
376 |
+
|
377 |
css = """
|
378 |
h1, h2, h3, h4, h5, h6, p, li, ul, ol, a, .centered-image {
|
379 |
text-align: center;
|
|
|
425 |
)
|
426 |
|
427 |
# Add login form
|
428 |
+
with gr.Row():
|
429 |
+
with gr.Column():
|
430 |
+
username = gr.Textbox(label="Username", placeholder="Enter your username", value="UDG")
|
431 |
+
password = gr.Textbox(label="Password", type="password", placeholder="Enter your password", value="UDG!")
|
432 |
+
with gr.Column():
|
433 |
+
login_button = gr.Button("Login")
|
434 |
+
login_error = gr.Markdown("Invalid username or password. Please try again.", visible=False)
|
435 |
|
436 |
|
437 |
with gr.Tab("QR Code and Prompt Input", visible=False) as app_container:
|
|
|
663 |
image_selector = gr.Dropdown(label="Select Image to Edit", choices=[], interactive=True, visible=False)
|
664 |
image_to_edit = gr.Image(label="Your Artistic QR Code", show_download_button=True, show_fullscreen_button=True)
|
665 |
|
666 |
+
with gr.Row():
|
667 |
+
qr_overlay = gr.Checkbox(label="Overlay Original QR Code", value=False)
|
668 |
+
qr_opacity = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="QR Overlay Opacity")
|
669 |
+
edge_enhance = gr.Slider(minimum=0.0, maximum=5.0, step=0.1, value=0.0, label="Edge Enhancement")
|
670 |
+
|
671 |
+
with gr.Row():
|
672 |
+
red_balance = gr.Slider(minimum=-1.0, maximum=1.0, step=0.1, value=0.0, label="Red Balance")
|
673 |
+
green_balance = gr.Slider(minimum=-1.0, maximum=1.0, step=0.1, value=0.0, label="Green Balance")
|
674 |
+
blue_balance = gr.Slider(minimum=-1.0, maximum=1.0, step=0.1, value=0.0, label="Blue Balance")
|
675 |
+
|
676 |
+
|
677 |
with gr.Row():
|
678 |
brightness = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Brightness")
|
679 |
contrast = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Contrast")
|
|
|
683 |
|
684 |
with gr.Row():
|
685 |
edited_image = gr.Image(label="Edited QR Code", show_download_button=True, show_fullscreen_button=True, visible=False)
|
686 |
+
scan_button = gr.Button("Verify QR Code Works", size="sm", visible=False)
|
687 |
+
scan_result = gr.Textbox(label="Validation Result of QR Code", interactive=False, visible=False)
|
688 |
|
689 |
used_seed = gr.Number(label="Seed Used", interactive=False)
|
690 |
|