broadfield-dev commited on
Commit
ce7d6e1
·
verified ·
1 Parent(s): 5bb1c00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -3,15 +3,28 @@ import re
3
 
4
  def update_ui(code):
5
  try:
6
- # This is a simplistic approach. In reality, you'd parse HTML and CSS to render UI.
7
- html_pattern = r'<[^>]+>'
8
- css_pattern = r'{[^}]*}'
9
-
10
- html = re.findall(html_pattern, code)
11
- css = re.findall(css_pattern, code)
 
 
 
 
 
 
 
12
 
13
- # For demonstration, we'll just combine HTML and CSS into one string.
14
- ui_output = ''.join(html) + ''.join(css)
 
 
 
 
 
 
15
  return ui_output, None
16
  except Exception as e:
17
  return "", str(e)
 
3
 
4
  def update_ui(code):
5
  try:
6
+ # Extract HTML and CSS
7
+ html_content = re.search(r'<html[^>]*>[\s\S]*<\/html>', code, re.IGNORECASE)
8
+ if html_content:
9
+ html_content = html_content.group(0)
10
+ else:
11
+ # If no <html> tag, assume all is HTML content
12
+ html_content = code
13
+
14
+ # Extract CSS if present in a <style> tag
15
+ css_content = re.search(r'<style[^>]*>[\s\S]*?<\/style>', code, re.IGNORECASE)
16
+ css_string = ''
17
+ if css_content:
18
+ css_string = css_content.group(0)
19
 
20
+ # Remove <style> tags for direct application
21
+ css_only = re.sub(r'<style>|<\/style>', '', css_string) if css_string else ''
22
+
23
+ # Combine HTML with CSS for preview
24
+ ui_output = f"""
25
+ <style>{css_only}</style>
26
+ {html_content}
27
+ """
28
  return ui_output, None
29
  except Exception as e:
30
  return "", str(e)