Spaces:
Running
Running
Commit
·
edb694c
1
Parent(s):
d758ffc
Update
Browse files- .gitignore +5 -1
- screencoder/config.json +1 -0
- screencoder/data/input/test1.png +2 -2
- screencoder/html_generator.py +7 -7
- screencoder/main.py +84 -0
.gitignore
CHANGED
@@ -1 +1,5 @@
|
|
1 |
-
.venv/
|
|
|
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
__pycache__/
|
3 |
+
*.pyc
|
4 |
+
*.pyo
|
5 |
+
*.pyd
|
screencoder/config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"api_key": "YOUR_API_KEY", "secret_key": "YOUR_SECRET_KEY"}
|
screencoder/data/input/test1.png
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|
screencoder/html_generator.py
CHANGED
@@ -4,13 +4,13 @@ import bs4
|
|
4 |
from threading import Thread
|
5 |
import time
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
# Prompt for each component
|
16 |
PROMPT_DICT = {
|
|
|
4 |
from threading import Thread
|
5 |
import time
|
6 |
|
7 |
+
# This dictionary can now be dynamically updated by an external script.
|
8 |
+
user_instruction = {
|
9 |
+
"sidebar": "Make all icons look better; fill in relevant English text; beautify the layout.",
|
10 |
+
"header": "Make the Google logo look better; change the avatar color to be more appealing.",
|
11 |
+
"navigation": "Please beautify the layout.",
|
12 |
+
"main content": "Based on the layout, please fill in appropriate English text and beautify the image blocks."
|
13 |
+
}
|
14 |
|
15 |
# Prompt for each component
|
16 |
PROMPT_DICT = {
|
screencoder/main.py
CHANGED
@@ -1,6 +1,44 @@
|
|
1 |
import subprocess
|
2 |
import sys
|
3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def run_script(script_path):
|
6 |
script_path = os.path.normpath(script_path)
|
@@ -36,6 +74,52 @@ def run_script(script_path):
|
|
36 |
print(f"An unexpected error occurred while running '{script_path}': {e}")
|
37 |
sys.exit(1)
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def main():
|
40 |
"""Main function to run the entire Screencoder workflow."""
|
41 |
print("Starting the Screencoder full workflow...")
|
|
|
1 |
import subprocess
|
2 |
import sys
|
3 |
import os
|
4 |
+
import json
|
5 |
+
|
6 |
+
|
7 |
+
# A simple placeholder for prompt injection
|
8 |
+
# In a real scenario, this should be a more robust mechanism
|
9 |
+
def inject_prompt_to_generator(prompt_text):
|
10 |
+
if not prompt_text:
|
11 |
+
return
|
12 |
+
|
13 |
+
# In this example, we assume the prompt is a simple string for the "main content"
|
14 |
+
# A more complex implementation would parse a structured prompt
|
15 |
+
user_instruction = {
|
16 |
+
"sidebar": "Make all icons look better; fill in relevant English text; beautify the layout.",
|
17 |
+
"header": "Make the Google logo look better; change the avatar color to be more appealing.",
|
18 |
+
"navigation": "Please beautify the layout.",
|
19 |
+
"main content": prompt_text
|
20 |
+
}
|
21 |
+
|
22 |
+
generator_path = os.path.join(os.path.dirname(__file__), 'html_generator.py')
|
23 |
+
with open(generator_path, 'r', encoding='utf-8') as f:
|
24 |
+
lines = f.readlines()
|
25 |
+
|
26 |
+
# Find the user_instruction dictionary and replace it
|
27 |
+
new_lines = []
|
28 |
+
in_dict = False
|
29 |
+
for line in lines:
|
30 |
+
if 'user_instruction = {' in line:
|
31 |
+
in_dict = True
|
32 |
+
new_lines.append(f"user_instruction = {json.dumps(user_instruction, indent=4)}\n")
|
33 |
+
elif in_dict and '}' in line:
|
34 |
+
in_dict = False
|
35 |
+
continue # Skip the closing brace of the old dict
|
36 |
+
elif not in_dict:
|
37 |
+
new_lines.append(line)
|
38 |
+
|
39 |
+
with open(generator_path, 'w', encoding='utf-8') as f:
|
40 |
+
f.writelines(new_lines)
|
41 |
+
|
42 |
|
43 |
def run_script(script_path):
|
44 |
script_path = os.path.normpath(script_path)
|
|
|
74 |
print(f"An unexpected error occurred while running '{script_path}': {e}")
|
75 |
sys.exit(1)
|
76 |
|
77 |
+
|
78 |
+
def generate_html_for_demo(image_path, prompt, output_dir="screencoder/data/output"):
|
79 |
+
"""
|
80 |
+
A modified workflow for the Gradio demo.
|
81 |
+
It takes an image path and a prompt, and returns the path to the final HTML file.
|
82 |
+
"""
|
83 |
+
print("Starting the Screencoder demo workflow...")
|
84 |
+
|
85 |
+
# Setup paths
|
86 |
+
project_root = os.path.dirname(__file__)
|
87 |
+
# The block_parsor script expects a specific input file name, so we must place our image there.
|
88 |
+
# IMPORTANT: This assumes a single-user-at-a-time workflow.
|
89 |
+
# For multi-user, you'd need isolated temp directories.
|
90 |
+
target_input_path = os.path.join(project_root, "data/input/test1.png")
|
91 |
+
|
92 |
+
# Ensure the input directory exists
|
93 |
+
os.makedirs(os.path.dirname(target_input_path), exist_ok=True)
|
94 |
+
|
95 |
+
# Copy the user-uploaded image to the location the script expects
|
96 |
+
import shutil
|
97 |
+
shutil.copy(image_path, target_input_path)
|
98 |
+
|
99 |
+
# --- Part 1: Initial Generation with Placeholders ---
|
100 |
+
print("\n--- Part 1: Initial Generation with Placeholders ---")
|
101 |
+
inject_prompt_to_generator(prompt)
|
102 |
+
run_script(os.path.join(project_root, "block_parsor.py"))
|
103 |
+
run_script(os.path.join(project_root, "html_generator.py"))
|
104 |
+
|
105 |
+
# --- Part 2: Final HTML Code Generation ---
|
106 |
+
print("\n--- Part 2: Final HTML Code Generation ---")
|
107 |
+
run_script(os.path.join(project_root, "image_box_detection.py"))
|
108 |
+
run_script(os.path.join(project_root, "UIED/run_single.py"))
|
109 |
+
run_script(os.path.join(project_root, "mapping.py"))
|
110 |
+
run_script(os.path.join(project_root, "image_replacer.py"))
|
111 |
+
|
112 |
+
final_html_path = os.path.join(output_dir, "test1_layout_final.html")
|
113 |
+
print(f"\nScreencoder demo workflow completed! Final HTML at: {final_html_path}")
|
114 |
+
|
115 |
+
# Check if the final file exists
|
116 |
+
if os.path.exists(final_html_path):
|
117 |
+
with open(final_html_path, 'r', encoding='utf-8') as f:
|
118 |
+
return f.read()
|
119 |
+
else:
|
120 |
+
return "<html><body><h1>Error: Final HTML not generated.</h1></body></html>"
|
121 |
+
|
122 |
+
|
123 |
def main():
|
124 |
"""Main function to run the entire Screencoder workflow."""
|
125 |
print("Starting the Screencoder full workflow...")
|