Spaces:
Running
Running
Commit
·
c4cfc0a
1
Parent(s):
fd9c8ec
debug
Browse files- app.py +0 -3
- screencoder/block_parsor.py +32 -3
- screencoder/main.py +7 -0
- screencoder/utils.py +18 -7
app.py
CHANGED
@@ -105,10 +105,8 @@ def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
105 |
Preview renderer with both width and height control for the inner canvas.
|
106 |
"""
|
107 |
try:
|
108 |
-
# Clean up the HTML code to remove problematic script and CSS references
|
109 |
soup = BeautifulSoup(code, 'html.parser')
|
110 |
|
111 |
-
# For preview, we'll just remove problematic references since we don't have the output_dir context
|
112 |
for script in soup.find_all('script'):
|
113 |
src = script.get('src', '')
|
114 |
if src and any(pattern in src for pattern in ['assets/', 'index-', 'iframeResizer']):
|
@@ -119,7 +117,6 @@ def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
119 |
if href and any(pattern in href for pattern in ['assets/', 'index-']):
|
120 |
link.decompose()
|
121 |
|
122 |
-
# Get the cleaned HTML
|
123 |
cleaned_code = str(soup)
|
124 |
|
125 |
except Exception as e:
|
|
|
105 |
Preview renderer with both width and height control for the inner canvas.
|
106 |
"""
|
107 |
try:
|
|
|
108 |
soup = BeautifulSoup(code, 'html.parser')
|
109 |
|
|
|
110 |
for script in soup.find_all('script'):
|
111 |
src = script.get('src', '')
|
112 |
if src and any(pattern in src for pattern in ['assets/', 'index-', 'iframeResizer']):
|
|
|
117 |
if href and any(pattern in href for pattern in ['assets/', 'index-']):
|
118 |
link.decompose()
|
119 |
|
|
|
120 |
cleaned_code = str(soup)
|
121 |
|
122 |
except Exception as e:
|
screencoder/block_parsor.py
CHANGED
@@ -226,14 +226,43 @@ def main():
|
|
226 |
json_output_path = os.path.join(tmp_dir, f"{run_id}_bboxes.json")
|
227 |
annotated_image_output_path = os.path.join(tmp_dir, f"{run_id}_with_bboxes.png")
|
228 |
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
exit(1)
|
232 |
|
233 |
print(f"--- Starting BBox Parsing for run_id: {run_id} ---")
|
234 |
|
235 |
client = Doubao(api_path)
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
bboxes = parse_bboxes(bbox_content)
|
238 |
|
239 |
if bboxes:
|
|
|
226 |
json_output_path = os.path.join(tmp_dir, f"{run_id}_bboxes.json")
|
227 |
annotated_image_output_path = os.path.join(tmp_dir, f"{run_id}_with_bboxes.png")
|
228 |
|
229 |
+
# Debug: Print all paths and check if files exist
|
230 |
+
print(f"Debug - base_dir: {base_dir}")
|
231 |
+
print(f"Debug - tmp_dir: {tmp_dir}")
|
232 |
+
print(f"Debug - image_path: {image_path}")
|
233 |
+
print(f"Debug - api_path: {api_path}")
|
234 |
+
print(f"Debug - image_path exists: {os.path.exists(image_path)}")
|
235 |
+
print(f"Debug - api_path exists: {os.path.exists(api_path)}")
|
236 |
+
|
237 |
+
# List contents of tmp_dir if it exists
|
238 |
+
if os.path.exists(tmp_dir):
|
239 |
+
print(f"Debug - tmp_dir contents: {os.listdir(tmp_dir)}")
|
240 |
+
else:
|
241 |
+
print(f"Debug - tmp_dir does not exist: {tmp_dir}")
|
242 |
+
|
243 |
+
if not os.path.exists(image_path):
|
244 |
+
print(f"Error: Input image not found at {image_path}")
|
245 |
+
# Create empty json file so the pipeline doesn't break
|
246 |
+
save_bboxes_to_json({}, json_output_path)
|
247 |
+
exit(1)
|
248 |
+
|
249 |
+
if not os.path.exists(api_path):
|
250 |
+
print(f"Error: API key file not found at {api_path}")
|
251 |
+
# Create empty json file so the pipeline doesn't break
|
252 |
+
save_bboxes_to_json({}, json_output_path)
|
253 |
exit(1)
|
254 |
|
255 |
print(f"--- Starting BBox Parsing for run_id: {run_id} ---")
|
256 |
|
257 |
client = Doubao(api_path)
|
258 |
+
base64_image = encode_image(image_path)
|
259 |
+
if not base64_image:
|
260 |
+
print(f"Error: Failed to encode image {image_path}")
|
261 |
+
# Create empty json file so the pipeline doesn't break
|
262 |
+
save_bboxes_to_json({}, json_output_path)
|
263 |
+
exit(1)
|
264 |
+
|
265 |
+
bbox_content = client.ask(PROMPT_MERGE, base64_image)
|
266 |
bboxes = parse_bboxes(bbox_content)
|
267 |
|
268 |
if bboxes:
|
screencoder/main.py
CHANGED
@@ -85,8 +85,15 @@ def generate_html_for_demo(image_path, instructions):
|
|
85 |
try:
|
86 |
# 1. Copy user-uploaded image to the temp input directory
|
87 |
new_image_path = tmp_dir / f"{run_id}.png"
|
|
|
|
|
|
|
88 |
img = Image.open(image_path)
|
89 |
img.save(new_image_path, "PNG")
|
|
|
|
|
|
|
|
|
90 |
|
91 |
# 2. Run the processing scripts in sequence
|
92 |
run_script_with_run_id("UIED/run_single.py", run_id)
|
|
|
85 |
try:
|
86 |
# 1. Copy user-uploaded image to the temp input directory
|
87 |
new_image_path = tmp_dir / f"{run_id}.png"
|
88 |
+
print(f"Debug - main.py: saving image from {image_path} to {new_image_path}")
|
89 |
+
print(f"Debug - main.py: image_path exists: {Path(image_path).exists()}")
|
90 |
+
|
91 |
img = Image.open(image_path)
|
92 |
img.save(new_image_path, "PNG")
|
93 |
+
|
94 |
+
print(f"Debug - main.py: saved image, new_image_path exists: {new_image_path.exists()}")
|
95 |
+
if new_image_path.exists():
|
96 |
+
print(f"Debug - main.py: saved image size: {new_image_path.stat().st_size} bytes")
|
97 |
|
98 |
# 2. Run the processing scripts in sequence
|
99 |
run_script_with_run_id("UIED/run_single.py", run_id)
|
screencoder/utils.py
CHANGED
@@ -11,19 +11,30 @@ import numpy as np
|
|
11 |
|
12 |
def encode_image(image):
|
13 |
if type(image) == str:
|
|
|
|
|
|
|
|
|
|
|
14 |
try:
|
15 |
with open(image, "rb") as image_file:
|
16 |
encoding = base64.b64encode(image_file.read()).decode('utf-8')
|
|
|
|
|
17 |
except Exception as e:
|
18 |
-
print(e)
|
19 |
-
|
20 |
-
encoding = base64.b64encode(image_file.read()).decode('utf-8')
|
21 |
-
return encoding
|
22 |
|
23 |
else:
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def image_mask(image_path: str, bbox_normalized: tuple[int, int, int, int]) -> Image.Image:
|
29 |
"""Creates a mask on the image in the specified normalized bounding box."""
|
|
|
11 |
|
12 |
def encode_image(image):
|
13 |
if type(image) == str:
|
14 |
+
print(f"Debug - encode_image: trying to encode {image}")
|
15 |
+
print(f"Debug - encode_image: file exists: {os.path.exists(image)}")
|
16 |
+
if os.path.exists(image):
|
17 |
+
print(f"Debug - encode_image: file size: {os.path.getsize(image)} bytes")
|
18 |
+
|
19 |
try:
|
20 |
with open(image, "rb") as image_file:
|
21 |
encoding = base64.b64encode(image_file.read()).decode('utf-8')
|
22 |
+
print(f"Debug - encode_image: successfully encoded, length: {len(encoding)}")
|
23 |
+
return encoding
|
24 |
except Exception as e:
|
25 |
+
print(f"Error encoding image {image}: {e}")
|
26 |
+
return None
|
|
|
|
|
27 |
|
28 |
else:
|
29 |
+
try:
|
30 |
+
buffered = io.BytesIO()
|
31 |
+
image.save(buffered, format="PNG")
|
32 |
+
encoding = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
33 |
+
print(f"Debug - encode_image: successfully encoded PIL image, length: {len(encoding)}")
|
34 |
+
return encoding
|
35 |
+
except Exception as e:
|
36 |
+
print(f"Error encoding PIL image: {e}")
|
37 |
+
return None
|
38 |
|
39 |
def image_mask(image_path: str, bbox_normalized: tuple[int, int, int, int]) -> Image.Image:
|
40 |
"""Creates a mask on the image in the specified normalized bounding box."""
|