Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,15 +3,28 @@ import re
|
|
3 |
|
4 |
def update_ui(code):
|
5 |
try:
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|