Spaces:
Paused
Paused
Commit ·
edb694c
1
Parent(s): d758ffc
Update
Browse filesFiles changed (5)
112345.venv/ .venv/__pycache__/*.pyc*.pyo*.pyd1{"api_key": "YOUR_API_KEY", "secret_key": "YOUR_SECRET_KEY"}3 unmodified lines45678910111213789101112131415163 unmodified linesfrom threading import Threadimport time
# user instruction for each component# user_instruction = {# "sidebar": "将所有的图标改为更加美观的样式;请你填充相应的适量有关的英文文字信息在其中;请你将布局美化",# "header": "将Google的logo更改美观;将头像颜色更改美观",# "navigation": "请你将布局美化",# "main content": "保持基本的布局不变,请你在对应的位置填充适量的关于elon trump的英文文本信息;将图像块的布局重新美化。"# }# This dictionary can now be dynamically updated by an external script.user_instruction = { "sidebar": "Make all icons look better; fill in relevant English text; beautify the layout.", "header": "Make the Google logo look better; change the avatar color to be more appealing.", "navigation": "Please beautify the layout.", "main content": "Based on the layout, please fill in appropriate English text and beautify the image blocks."}
# Prompt for each componentPROMPT_DICT = {123456789101112131415161718192021222324252627282930313233343536373839404142434429 unmodified lines7475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import subprocessimport sysimport osimport json
# A simple placeholder for prompt injection# In a real scenario, this should be a more robust mechanismdef inject_prompt_to_generator(prompt_text): if not prompt_text: return
# In this example, we assume the prompt is a simple string for the "main content" # A more complex implementation would parse a structured prompt user_instruction = { "sidebar": "Make all icons look better; fill in relevant English text; beautify the layout.", "header": "Make the Google logo look better; change the avatar color to be more appealing.", "navigation": "Please beautify the layout.", "main content": prompt_text } generator_path = os.path.join(os.path.dirname(__file__), 'html_generator.py') with open(generator_path, 'r', encoding='utf-8') as f: lines = f.readlines() # Find the user_instruction dictionary and replace it new_lines = [] in_dict = False for line in lines: if 'user_instruction = {' in line: in_dict = True new_lines.append(f"user_instruction = {json.dumps(user_instruction, indent=4)}\n") elif in_dict and '}' in line: in_dict = False continue # Skip the closing brace of the old dict elif not in_dict: new_lines.append(line)
with open(generator_path, 'w', encoding='utf-8') as f: f.writelines(new_lines)
def run_script(script_path): script_path = os.path.normpath(script_path)29 unmodified lines print(f"An unexpected error occurred while running '{script_path}': {e}") sys.exit(1)
def generate_html_for_demo(image_path, prompt, output_dir="screencoder/data/output"): """ A modified workflow for the Gradio demo. It takes an image path and a prompt, and returns the path to the final HTML file. """ print("Starting the Screencoder demo workflow...")
# Setup paths project_root = os.path.dirname(__file__) # The block_parsor script expects a specific input file name, so we must place our image there. # IMPORTANT: This assumes a single-user-at-a-time workflow. # For multi-user, you'd need isolated temp directories. target_input_path = os.path.join(project_root, "data/input/test1.png") # Ensure the input directory exists os.makedirs(os.path.dirname(target_input_path), exist_ok=True)
# Copy the user-uploaded image to the location the script expects import shutil shutil.copy(image_path, target_input_path)
# --- Part 1: Initial Generation with Placeholders --- print("\n--- Part 1: Initial Generation with Placeholders ---") inject_prompt_to_generator(prompt) run_script(os.path.join(project_root, "block_parsor.py")) run_script(os.path.join(project_root, "html_generator.py"))
# --- Part 2: Final HTML Code Generation --- print("\n--- Part 2: Final HTML Code Generation ---") run_script(os.path.join(project_root, "image_box_detection.py")) run_script(os.path.join(project_root, "UIED/run_single.py")) run_script(os.path.join(project_root, "mapping.py")) run_script(os.path.join(project_root, "image_replacer.py"))
final_html_path = os.path.join(output_dir, "test1_layout_final.html") print(f"\nScreencoder demo workflow completed! Final HTML at: {final_html_path}")
# Check if the final file exists if os.path.exists(final_html_path): with open(final_html_path, 'r', encoding='utf-8') as f: return f.read() else: return "<html><body><h1>Error: Final HTML not generated.</h1></body></html>"
def main(): """Main function to run the entire Screencoder workflow.""" print("Starting the Screencoder full workflow...").gitignore+5-1
screencoder/config.jsonAdded+1
screencoder/data/input/test1.png

Large File Pointer Details
- SHA256: b832febac9fd78a25da618e1fddf0d5a524916b1cdf5e8c93c3839643e28597b
- Pointer size: 132 Bytes
- Size of remote file: 3.43 MB

Large File Pointer Details
- SHA256: fdc55e266f9b6b0ed42ec9e388223b1326a95817f7f4ecd69aab17934b364cba
- Pointer size: 132 Bytes
- Size of remote file: 3.24 MB
screencoder/html_generator.py+7-7
screencoder/main.py+84