Spaces:
Running
Running
Commit
·
cec0dbe
1
Parent(s):
85d7518
Update
Browse files- app.py +4 -4
- screencoder/data/input/draft.png +3 -0
- screencoder/image_replacer.py +13 -5
app.py
CHANGED
|
@@ -23,20 +23,20 @@ examples_data = [
|
|
| 23 |
"screencoder/data/input/test1.png"
|
| 24 |
],
|
| 25 |
[
|
| 26 |
-
"screencoder/data/input/
|
| 27 |
"",
|
| 28 |
"",
|
| 29 |
"",
|
| 30 |
"",
|
| 31 |
-
"screencoder/data/input/
|
| 32 |
],
|
| 33 |
[
|
| 34 |
-
"screencoder/data/input/
|
| 35 |
"",
|
| 36 |
"",
|
| 37 |
"",
|
| 38 |
"",
|
| 39 |
-
"screencoder/data/input/
|
| 40 |
],
|
| 41 |
]
|
| 42 |
example_rows = [row[:5] for row in examples_data]
|
|
|
|
| 23 |
"screencoder/data/input/test1.png"
|
| 24 |
],
|
| 25 |
[
|
| 26 |
+
"screencoder/data/input/test3.png",
|
| 27 |
"",
|
| 28 |
"",
|
| 29 |
"",
|
| 30 |
"",
|
| 31 |
+
"screencoder/data/input/test3.png"
|
| 32 |
],
|
| 33 |
[
|
| 34 |
+
"screencoder/data/input/draft.png",
|
| 35 |
"",
|
| 36 |
"",
|
| 37 |
"",
|
| 38 |
"",
|
| 39 |
+
"screencoder/data/input/draft.png"
|
| 40 |
],
|
| 41 |
]
|
| 42 |
example_rows = [row[:5] for row in examples_data]
|
screencoder/data/input/draft.png
ADDED
|
Git LFS Details
|
screencoder/image_replacer.py
CHANGED
|
@@ -99,7 +99,7 @@ def main():
|
|
| 99 |
soup = BeautifulSoup(html_content, 'html.parser')
|
| 100 |
|
| 101 |
# 1. Find all placeholder elements by their class, in document order.
|
| 102 |
-
placeholder_elements = soup.find_all('
|
| 103 |
|
| 104 |
# 2. Get the placeholder IDs from the mapping file in the correct, sorted order.
|
| 105 |
def natural_sort_key(s):
|
|
@@ -132,10 +132,18 @@ def main():
|
|
| 132 |
# Debug: Print the path being used
|
| 133 |
print(f"Setting image path for {ph_id}: {relative_img_path}")
|
| 134 |
|
| 135 |
-
# ---
|
| 136 |
-
#
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
# Save the modified HTML
|
| 141 |
final_html_path.write_text(str(soup))
|
|
|
|
| 99 |
soup = BeautifulSoup(html_content, 'html.parser')
|
| 100 |
|
| 101 |
# 1. Find all placeholder elements by their class, in document order.
|
| 102 |
+
placeholder_elements = soup.find_all(class_='bg-gray-400')
|
| 103 |
|
| 104 |
# 2. Get the placeholder IDs from the mapping file in the correct, sorted order.
|
| 105 |
def natural_sort_key(s):
|
|
|
|
| 132 |
# Debug: Print the path being used
|
| 133 |
print(f"Setting image path for {ph_id}: {relative_img_path}")
|
| 134 |
|
| 135 |
+
# --- Convert div with bg-gray-400 class to img tag ---
|
| 136 |
+
# Create a new img element
|
| 137 |
+
new_img = soup.new_tag('img')
|
| 138 |
+
new_img['src'] = relative_img_path
|
| 139 |
+
new_img['class'] = ph_element.get('class', [])
|
| 140 |
+
# Remove bg-gray-400 class and add appropriate image classes
|
| 141 |
+
if 'bg-gray-400' in new_img['class']:
|
| 142 |
+
new_img['class'].remove('bg-gray-400')
|
| 143 |
+
new_img['class'].extend(['w-full', 'h-full', 'object-cover'])
|
| 144 |
+
|
| 145 |
+
# Replace the div element with the new img element
|
| 146 |
+
ph_element.replace_with(new_img)
|
| 147 |
|
| 148 |
# Save the modified HTML
|
| 149 |
final_html_path.write_text(str(soup))
|