Spaces:
Running
Running
Commit
·
32c38a5
1
Parent(s):
c5a511a
retrieve
Browse files
app.py
CHANGED
@@ -126,11 +126,10 @@ def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
126 |
|
127 |
safe_code = html.escape(cleaned_code).replace("'", "'")
|
128 |
iframe_html = f"""
|
129 |
-
<div style="width: 100%; max-width:
|
130 |
<div style="
|
131 |
-
width:
|
132 |
-
|
133 |
-
height: 600px;
|
134 |
margin: 0 auto;
|
135 |
display: flex;
|
136 |
justify-content: center;
|
@@ -144,7 +143,7 @@ def render_preview(code: str, width: int, height: int, scale: float) -> str:
|
|
144 |
width: {width}px;
|
145 |
height: {height}px;
|
146 |
transform: scale({scale});
|
147 |
-
transform-origin:
|
148 |
border: none;
|
149 |
position: relative;">
|
150 |
<iframe
|
@@ -238,116 +237,45 @@ def process_and_generate(image_np, image_path_from_state, sidebar_prompt, header
|
|
238 |
|
239 |
return initial_preview, html_content, gr.update(value=package_url, visible=True)
|
240 |
|
241 |
-
with gr.Blocks(
|
242 |
-
.
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
width: 33%;
|
256 |
-
min-width: 350px;
|
257 |
-
overflow-y: auto;
|
258 |
-
padding: 20px;
|
259 |
-
border-right: 1px solid #e0e0e0;
|
260 |
-
background: #fafafa;
|
261 |
-
display: flex;
|
262 |
-
flex-direction: column;
|
263 |
-
}
|
264 |
-
.right-column {
|
265 |
-
flex: 1;
|
266 |
-
overflow-y: auto;
|
267 |
-
padding: 20px;
|
268 |
-
background: white;
|
269 |
-
display: flex;
|
270 |
-
flex-direction: column;
|
271 |
-
}
|
272 |
-
.header {
|
273 |
-
padding: 20px;
|
274 |
-
border-bottom: 1px solid #e0e0e0;
|
275 |
-
background: white;
|
276 |
-
flex-shrink: 0;
|
277 |
-
}
|
278 |
-
.examples-section {
|
279 |
-
padding: 20px;
|
280 |
-
border-top: 1px solid #e0e0e0;
|
281 |
-
background: #f5f5f5;
|
282 |
-
flex-shrink: 0;
|
283 |
-
}
|
284 |
-
.left-column > * {
|
285 |
-
margin-bottom: 15px;
|
286 |
-
}
|
287 |
-
.right-column .tabs {
|
288 |
-
flex: 1;
|
289 |
-
display: flex;
|
290 |
-
flex-direction: column;
|
291 |
-
}
|
292 |
-
.right-column .tab-nav {
|
293 |
-
flex-shrink: 0;
|
294 |
-
}
|
295 |
-
.right-column .tab-content {
|
296 |
-
flex: 1;
|
297 |
-
overflow: auto;
|
298 |
-
}
|
299 |
-
@media (max-width: 768px) {
|
300 |
-
.content-row {
|
301 |
-
flex-direction: column;
|
302 |
-
}
|
303 |
-
.left-column, .right-column {
|
304 |
-
width: 100%;
|
305 |
-
min-width: auto;
|
306 |
-
}
|
307 |
-
}
|
308 |
-
""") as demo:
|
309 |
-
with gr.Column(elem_classes=["main-container"]):
|
310 |
-
with gr.Column(elem_classes=["header"]):
|
311 |
-
gr.Markdown("# ScreenCoder: Screenshot to Code")
|
312 |
-
|
313 |
-
with gr.Row(elem_classes=["content-row"]):
|
314 |
-
with gr.Column(elem_classes=["left-column"]):
|
315 |
-
gr.Markdown("### Step 1: Provide an Image")
|
316 |
-
active_image = gr.Image(type="numpy", height=400, value=examples_data[0][0])
|
317 |
-
upload_button = gr.UploadButton("Click to Upload", file_types=["image"], variant="primary")
|
318 |
-
|
319 |
-
gr.Markdown("### Step 2: Write Prompts (Optional)")
|
320 |
-
with gr.Accordion("Component-specific Prompts", open=False):
|
321 |
-
sidebar_prompt = gr.Textbox(label="Sidebar", placeholder="Instructions for the sidebar...")
|
322 |
-
header_prompt = gr.Textbox(label="Header", placeholder="Instructions for the header...")
|
323 |
-
navigation_prompt = gr.Textbox(label="Navigation", placeholder="Instructions for the navigation...")
|
324 |
-
main_content_prompt = gr.Textbox(label="Main Content", placeholder="Instructions for the main content...")
|
325 |
|
326 |
-
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
|
338 |
-
|
339 |
-
|
340 |
|
341 |
-
|
342 |
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
)
|
351 |
|
352 |
active_image_path_state = gr.State(examples_data[0][5])
|
353 |
|
|
|
126 |
|
127 |
safe_code = html.escape(cleaned_code).replace("'", "'")
|
128 |
iframe_html = f"""
|
129 |
+
<div style="width: 100%; max-width: 1920px; margin: 0 auto; overflow-x: auto; overflow-y: hidden;">
|
130 |
<div style="
|
131 |
+
width: 1920px;
|
132 |
+
height: 1000px;
|
|
|
133 |
margin: 0 auto;
|
134 |
display: flex;
|
135 |
justify-content: center;
|
|
|
143 |
width: {width}px;
|
144 |
height: {height}px;
|
145 |
transform: scale({scale});
|
146 |
+
transform-origin: left center;
|
147 |
border: none;
|
148 |
position: relative;">
|
149 |
<iframe
|
|
|
237 |
|
238 |
return initial_preview, html_content, gr.update(value=package_url, visible=True)
|
239 |
|
240 |
+
with gr.Blocks() as demo:
|
241 |
+
gr.Markdown("# ScreenCoder: Screenshot to Code")
|
242 |
+
with gr.Row():
|
243 |
+
with gr.Column(scale=1):
|
244 |
+
gr.Markdown("### Step 1: Provide an Image")
|
245 |
+
active_image = gr.Image(type="numpy", height=400, value=examples_data[0][0])
|
246 |
+
upload_button = gr.UploadButton("Click to Upload", file_types=["image"], variant="primary")
|
247 |
+
|
248 |
+
gr.Markdown("### Step 2: Write Prompts (Optional)")
|
249 |
+
with gr.Accordion("Component-specific Prompts", open=False):
|
250 |
+
sidebar_prompt = gr.Textbox(label="Sidebar", placeholder="Instructions for the sidebar...")
|
251 |
+
header_prompt = gr.Textbox(label="Header", placeholder="Instructions for the header...")
|
252 |
+
navigation_prompt = gr.Textbox(label="Navigation", placeholder="Instructions for the navigation...")
|
253 |
+
main_content_prompt = gr.Textbox(label="Main Content", placeholder="Instructions for the main content...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
+
generate_btn = gr.Button("Generate HTML", variant="primary")
|
256 |
|
257 |
+
with gr.Column(scale=2):
|
258 |
+
with gr.Tabs():
|
259 |
+
with gr.TabItem("Preview"):
|
260 |
+
with gr.Row():
|
261 |
+
scale_slider = gr.Slider(0.2, 1.5, value=0.7, step=0.05, label="Zoom")
|
262 |
+
width_slider = gr.Slider(400, 1920, value=1280, step=100, label="Canvas Width (px)")
|
263 |
+
height_slider = gr.Slider(300, 1080, value=600, step=50, label="Canvas Height (px)")
|
264 |
+
|
265 |
+
html_preview = gr.HTML(label="Rendered HTML", show_label=False)
|
266 |
|
267 |
+
with gr.TabItem("Code"):
|
268 |
+
html_code_output = gr.Code(label="Generated HTML", language="html")
|
269 |
|
270 |
+
download_button = gr.Button("⬇️ Download Package", visible=False, variant="secondary")
|
271 |
|
272 |
+
gr.Examples(
|
273 |
+
examples=examples_data,
|
274 |
+
fn=lambda *args: args[0],
|
275 |
+
inputs=[gr.State(examples_data[0][0])],
|
276 |
+
outputs=[active_image],
|
277 |
+
cache_examples=False,
|
278 |
+
)
|
|
|
279 |
|
280 |
active_image_path_state = gr.State(examples_data[0][5])
|
281 |
|