Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,8 @@ import zipfile
|
|
7 |
from PIL import Image
|
8 |
|
9 |
# --- Required Core Logic ---
|
10 |
-
# These functions are copied from your project's core modules.
|
11 |
# Ensure keylock1 and repo_to_md are in the same directory or accessible in the Python path.
|
12 |
-
from
|
13 |
from repo_to_md.core import markdown_to_files
|
14 |
|
15 |
# --- Helper Functions for the Decoder UI ---
|
@@ -17,6 +16,7 @@ from repo_to_md.core import markdown_to_files
|
|
17 |
def retrieve_and_process_files(stego_image_pil: Image.Image, password: str):
|
18 |
"""
|
19 |
Extracts data from an image and prepares the file browser UI components for update.
|
|
|
20 |
"""
|
21 |
# Initial state for all UI components
|
22 |
status = "An error occurred."
|
@@ -30,12 +30,11 @@ def retrieve_and_process_files(stego_image_pil: Image.Image, password: str):
|
|
30 |
status = "Error: Please upload or paste an image."
|
31 |
return status, file_data_state, file_buffers_state, file_browser_visibility, filename_choices, accordion_update, code_update
|
32 |
|
33 |
-
|
34 |
-
status = "Error: Please enter a decryption password."
|
35 |
-
return status, file_data_state, file_buffers_state, file_browser_visibility, filename_choices, accordion_update, code_update
|
36 |
|
37 |
try:
|
38 |
-
# Step 1: Extract and decrypt data from the image
|
|
|
39 |
extracted_data = keylock_core.extract_data_from_image(stego_image_pil.convert("RGB"))
|
40 |
decrypted_bytes = keylock_core.decrypt_data(extracted_data, password)
|
41 |
|
@@ -67,8 +66,8 @@ def retrieve_and_process_files(stego_image_pil: Image.Image, password: str):
|
|
67 |
else:
|
68 |
status += " (No files were found in the decoded content)."
|
69 |
|
70 |
-
except ValueError
|
71 |
-
status =
|
72 |
except Exception as e:
|
73 |
status = f"An unexpected error occurred: {e}"
|
74 |
|
@@ -103,7 +102,7 @@ def download_all_zip(buffers):
|
|
103 |
# --- GRADIO UI DEFINITION ---
|
104 |
with gr.Blocks(theme=gr.themes.Soft(), title="KeyLock Decoder") as demo:
|
105 |
gr.Markdown("# KeyLock Image Decoder")
|
106 |
-
gr.Markdown("Upload or paste your KeyLock image, enter the password, and click 'Extract Files' to view and download the contents.")
|
107 |
|
108 |
# State variables to hold data between user interactions
|
109 |
file_data_state = gr.State([])
|
@@ -118,9 +117,10 @@ with gr.Blocks(theme=gr.themes.Soft(), title="KeyLock Decoder") as demo:
|
|
118 |
sources=["upload", "clipboard"]
|
119 |
)
|
120 |
extract_password_input = gr.Textbox(
|
121 |
-
label="Decryption Password",
|
122 |
type="password",
|
123 |
-
placeholder="
|
|
|
124 |
)
|
125 |
extract_button = gr.Button(
|
126 |
value="Extract Files",
|
|
|
7 |
from PIL import Image
|
8 |
|
9 |
# --- Required Core Logic ---
|
|
|
10 |
# Ensure keylock1 and repo_to_md are in the same directory or accessible in the Python path.
|
11 |
+
from keylock1 import core as keylock_core
|
12 |
from repo_to_md.core import markdown_to_files
|
13 |
|
14 |
# --- Helper Functions for the Decoder UI ---
|
|
|
16 |
def retrieve_and_process_files(stego_image_pil: Image.Image, password: str):
|
17 |
"""
|
18 |
Extracts data from an image and prepares the file browser UI components for update.
|
19 |
+
This version handles cases where the password is an empty string.
|
20 |
"""
|
21 |
# Initial state for all UI components
|
22 |
status = "An error occurred."
|
|
|
30 |
status = "Error: Please upload or paste an image."
|
31 |
return status, file_data_state, file_buffers_state, file_browser_visibility, filename_choices, accordion_update, code_update
|
32 |
|
33 |
+
# The check for a mandatory password has been removed. An empty string is now a valid input.
|
|
|
|
|
34 |
|
35 |
try:
|
36 |
+
# Step 1: Extract and decrypt data from the image.
|
37 |
+
# The password (which can be empty) is passed directly to the core function.
|
38 |
extracted_data = keylock_core.extract_data_from_image(stego_image_pil.convert("RGB"))
|
39 |
decrypted_bytes = keylock_core.decrypt_data(extracted_data, password)
|
40 |
|
|
|
66 |
else:
|
67 |
status += " (No files were found in the decoded content)."
|
68 |
|
69 |
+
except ValueError:
|
70 |
+
status = "Error: Failed to decrypt. This usually means the password is wrong (or was required but not provided)."
|
71 |
except Exception as e:
|
72 |
status = f"An unexpected error occurred: {e}"
|
73 |
|
|
|
102 |
# --- GRADIO UI DEFINITION ---
|
103 |
with gr.Blocks(theme=gr.themes.Soft(), title="KeyLock Decoder") as demo:
|
104 |
gr.Markdown("# KeyLock Image Decoder")
|
105 |
+
gr.Markdown("Upload or paste your KeyLock image, enter the password (if one was used), and click 'Extract Files' to view and download the contents.")
|
106 |
|
107 |
# State variables to hold data between user interactions
|
108 |
file_data_state = gr.State([])
|
|
|
117 |
sources=["upload", "clipboard"]
|
118 |
)
|
119 |
extract_password_input = gr.Textbox(
|
120 |
+
label="Decryption Password (Optional)",
|
121 |
type="password",
|
122 |
+
placeholder="Leave blank if no password was set",
|
123 |
+
info="If a password was used during encryption, it is required here."
|
124 |
)
|
125 |
extract_button = gr.Button(
|
126 |
value="Extract Files",
|