Jimmyzheng-10 commited on
Commit
0bdc733
Β·
1 Parent(s): 192498b
Files changed (1) hide show
  1. app.py +129 -24
app.py CHANGED
@@ -220,7 +220,7 @@ def process_and_generate(image_input, image_path_from_state, sidebar_prompt, hea
220
  img['src'] = original_src # Keep original if not found
221
 
222
  processed_html = str(soup)
223
- preview = render_preview(processed_html, 1920, 1080, 0.7)
224
  return preview, processed_html
225
 
226
  # --- Process both HTML versions ---
@@ -244,42 +244,147 @@ def process_and_generate(image_input, image_path_from_state, sidebar_prompt, hea
244
  return layout_preview, final_preview, final_code, layout_code, final_code, gr.update(value=package_url, visible=True)
245
 
246
 
247
- with gr.Blocks() as demo:
248
- gr.Markdown("# ScreenCoder: Screenshot to Code")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  with gr.Row():
250
  with gr.Column(scale=1):
251
- gr.Markdown("### Step 1: Provide an Image")
252
  active_image = gr.Image(type="filepath", height=400)
253
- upload_button = gr.UploadButton("Click to Upload", file_types=["image"], variant="primary")
254
 
255
- gr.Markdown("### Step 2: Write Prompts (Optional)")
256
- with gr.Accordion("Component-specific Prompts", open=False):
257
- sidebar_prompt = gr.Textbox(label="Sidebar", placeholder="Instructions for the sidebar...")
258
- header_prompt = gr.Textbox(label="Header", placeholder="Instructions for the header...")
259
- navigation_prompt = gr.Textbox(label="Navigation", placeholder="Instructions for the navigation...")
260
- main_content_prompt = gr.Textbox(label="Main Content", placeholder="Instructions for the main content...")
261
 
262
- generate_btn = gr.Button("Generate HTML", variant="primary")
263
 
264
  with gr.Column(scale=2):
265
- gr.Markdown("### Preview Area")
266
- gr.Markdown("**Tip**: Use the sliders below to adjust the preview size and zoom level for better viewing experience. You can also adjust the page's viewing angle by swiping up, down, left, or right.")
267
  with gr.Tabs():
268
- with gr.TabItem("Preview"):
269
  with gr.Row():
270
- scale_slider = gr.Slider(0.2, 1.5, value=0.55, step=0.05, label="Zoom")
271
- width_slider = gr.Slider(400, 2000, value=1920, step=100, label="Canvas Width (px)")
272
- height_slider = gr.Slider(300, 1200, value=1080, step=50, label="Canvas Height (px)")
273
 
274
  html_preview = gr.HTML(label="Rendered HTML", show_label=False)
275
- with gr.TabItem("Preview With Placeholder"):
276
  with gr.Row():
277
- scale_slider_with_placeholder = gr.Slider(0.2, 1.5, value=0.7, step=0.05, label="Zoom")
278
- width_slider_with_placeholder = gr.Slider(400, 2000, value=1920, step=100, label="Canvas Width (px)")
279
- height_slider_with_placeholder = gr.Slider(300, 1200, value=1080, step=50, label="Canvas Height (px)")
280
 
281
  html_preview_with_placeholder = gr.HTML(label="Rendered HTML", show_label=False)
282
- with gr.TabItem("Code"):
283
  html_code_output = gr.Code(label="Generated HTML", language="html")
284
 
285
  download_button = gr.Button("⬇️ Download Package", visible=False, variant="secondary")
@@ -288,7 +393,7 @@ with gr.Blocks() as demo:
288
  examples=example_rows,
289
  inputs=[active_image, sidebar_prompt, header_prompt, navigation_prompt, main_content_prompt],
290
  cache_examples=False,
291
- label="Examples"
292
  )
293
 
294
  # State to hold the HTML content for each preview tab
 
220
  img['src'] = original_src # Keep original if not found
221
 
222
  processed_html = str(soup)
223
+ preview = render_preview(processed_html, 1920, 1080, 0.55)
224
  return preview, processed_html
225
 
226
  # --- Process both HTML versions ---
 
244
  return layout_preview, final_preview, final_code, layout_code, final_code, gr.update(value=package_url, visible=True)
245
 
246
 
247
+ with gr.Blocks(css="""
248
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
249
+
250
+ * {
251
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
252
+ }
253
+
254
+ h1, h2, h3, h4, h5, h6 {
255
+ font-weight: 600 !important;
256
+ color: #1f2937 !important;
257
+ letter-spacing: -0.025em !important;
258
+ }
259
+
260
+ h1 {
261
+ font-size: 2.25rem !important;
262
+ font-weight: 700 !important;
263
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
264
+ -webkit-background-clip: text;
265
+ -webkit-text-fill-color: transparent;
266
+ background-clip: text;
267
+ margin-bottom: 1.5rem !important;
268
+ }
269
+
270
+ h2 {
271
+ font-size: 1.5rem !important;
272
+ font-weight: 600 !important;
273
+ color: #374151 !important;
274
+ margin-bottom: 1rem !important;
275
+ }
276
+
277
+ .gr-button {
278
+ font-weight: 500 !important;
279
+ border-radius: 8px !important;
280
+ transition: all 0.2s ease !important;
281
+ }
282
+
283
+ .gr-button:hover {
284
+ transform: translateY(-1px) !important;
285
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
286
+ }
287
+
288
+ .gr-textbox, .gr-slider {
289
+ border-radius: 8px !important;
290
+ }
291
+
292
+ .gr-textbox input, .gr-textbox textarea {
293
+ font-family: 'Inter', sans-serif !important;
294
+ font-size: 14px !important;
295
+ }
296
+
297
+ .gr-slider {
298
+ font-family: 'Inter', sans-serif !important;
299
+ }
300
+
301
+ .gr-tabs {
302
+ border-radius: 12px !important;
303
+ overflow: hidden !important;
304
+ }
305
+
306
+ .gr-tab-nav {
307
+ background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%) !important;
308
+ }
309
+
310
+ .gr-tab-nav button {
311
+ font-weight: 500 !important;
312
+ color: #64748b !important;
313
+ transition: all 0.2s ease !important;
314
+ }
315
+
316
+ .gr-tab-nav button.selected {
317
+ color: #3b82f6 !important;
318
+ background: white !important;
319
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
320
+ }
321
+
322
+ .gr-accordion {
323
+ border-radius: 8px !important;
324
+ border: 1px solid #e5e7eb !important;
325
+ }
326
+
327
+ .gr-accordion-header {
328
+ font-weight: 500 !important;
329
+ color: #374151 !important;
330
+ }
331
+
332
+ .gr-markdown {
333
+ font-family: 'Inter', sans-serif !important;
334
+ line-height: 1.6 !important;
335
+ }
336
+
337
+ .gr-markdown strong {
338
+ color: #059669 !important;
339
+ font-weight: 600 !important;
340
+ }
341
+
342
+ .gr-examples {
343
+ border-radius: 12px !important;
344
+ border: 1px solid #e5e7eb !important;
345
+ background: #f9fafb !important;
346
+ }
347
+
348
+ .gr-examples-header {
349
+ font-weight: 600 !important;
350
+ color: #374151 !important;
351
+ }
352
+ """) as demo:
353
+ gr.Markdown("# 🎨 ScreenCoder: Screenshot to Code")
354
  with gr.Row():
355
  with gr.Column(scale=1):
356
+ gr.Markdown("## πŸ“Έ Step 1: Provide an Image")
357
  active_image = gr.Image(type="filepath", height=400)
358
+ upload_button = gr.UploadButton("πŸ“ Click to Upload", file_types=["image"], variant="primary")
359
 
360
+ gr.Markdown("## ✍️ Step 2: Write Prompts (Optional)")
361
+ with gr.Accordion("🎯 Component-specific Prompts", open=False):
362
+ sidebar_prompt = gr.Textbox(label="πŸ“‹ Sidebar", placeholder="Instructions for the sidebar...")
363
+ header_prompt = gr.Textbox(label="πŸ“ Header", placeholder="Instructions for the header...")
364
+ navigation_prompt = gr.Textbox(label="🧭 Navigation", placeholder="Instructions for the navigation...")
365
+ main_content_prompt = gr.Textbox(label="πŸ“„ Main Content", placeholder="Instructions for the main content...")
366
 
367
+ generate_btn = gr.Button("πŸš€ Generate HTML", variant="primary")
368
 
369
  with gr.Column(scale=2):
370
+ gr.Markdown("## πŸ‘€ Preview Area")
371
+ gr.Markdown("**πŸ’‘ Tips**: - Use the sliders below to adjust the preview size and zoom level for better viewing experience. - You can also adjust the page's viewing angle by swiping up, down, left, or right.")
372
  with gr.Tabs():
373
+ with gr.TabItem("πŸ–ΌοΈ Preview"):
374
  with gr.Row():
375
+ scale_slider = gr.Slider(0.2, 1.5, value=0.55, step=0.05, label="πŸ” Zoom")
376
+ width_slider = gr.Slider(400, 2000, value=1920, step=50, label="πŸ“ Canvas Width (px)")
377
+ height_slider = gr.Slider(300, 1200, value=1080, step=50, label="πŸ“ Canvas Height (px)")
378
 
379
  html_preview = gr.HTML(label="Rendered HTML", show_label=False)
380
+ with gr.TabItem("🎨 Preview With Placeholder"):
381
  with gr.Row():
382
+ scale_slider_with_placeholder = gr.Slider(0.2, 1.5, value=0.55, step=0.05, label="πŸ” Zoom")
383
+ width_slider_with_placeholder = gr.Slider(400, 2000, value=1920, step=100, label="πŸ“ Canvas Width (px)")
384
+ height_slider_with_placeholder = gr.Slider(300, 1200, value=1080, step=50, label="πŸ“ Canvas Height (px)")
385
 
386
  html_preview_with_placeholder = gr.HTML(label="Rendered HTML", show_label=False)
387
+ with gr.TabItem("πŸ’» Code"):
388
  html_code_output = gr.Code(label="Generated HTML", language="html")
389
 
390
  download_button = gr.Button("⬇️ Download Package", visible=False, variant="secondary")
 
393
  examples=example_rows,
394
  inputs=[active_image, sidebar_prompt, header_prompt, navigation_prompt, main_content_prompt],
395
  cache_examples=False,
396
+ label="πŸ“š Examples"
397
  )
398
 
399
  # State to hold the HTML content for each preview tab