Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Add HTML redesign functionality with TailwindCSS support and update Gradio interface
Browse files
app.py
CHANGED
@@ -110,9 +110,34 @@ def extract_html_from_response(response_text):
|
|
110 |
raise ValueError("No HTML content found in the response")
|
111 |
|
112 |
|
113 |
-
def
|
114 |
-
"""
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
# Check if HF_TOKEN is set
|
117 |
hf_token = os.getenv("HF_TOKEN")
|
118 |
if not hf_token:
|
@@ -125,13 +150,11 @@ def chat_with_deepseek(message, history):
|
|
125 |
"Content-Type": "application/json",
|
126 |
}
|
127 |
|
128 |
-
# Build
|
129 |
-
messages = [
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
messages.append({"role": "assistant", "content": assistant})
|
134 |
-
messages.append({"role": "user", "content": message})
|
135 |
|
136 |
data = {
|
137 |
"messages": messages,
|
@@ -150,8 +173,7 @@ def chat_with_deepseek(message, history):
|
|
150 |
# Extract HTML from the response
|
151 |
try:
|
152 |
html_content = extract_html_from_response(response_content)
|
153 |
-
|
154 |
-
return f"```html\n{html_content}\n```"
|
155 |
except ValueError as e:
|
156 |
return f"Error: {str(e)}. Response was: {response_content[:200]}..."
|
157 |
|
@@ -186,19 +208,40 @@ custom_css = """
|
|
186 |
"""
|
187 |
|
188 |
# Create Gradio interface
|
189 |
-
demo = gr.
|
190 |
-
fn=
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
examples=[
|
194 |
-
'<div class="p-4 border"><h1 class="text-xl">Welcome</h1><p>This is a basic card</p><button class="bg-blue-500 text-white px-4 py-2">Click me</button></div>',
|
195 |
-
'<form class="space-y-4"><input type="email" placeholder="Email" class="border p-2 w-full"><input type="password" placeholder="Password" class="border p-2 w-full"><button type="submit" class="bg-green-500 text-white p-2">Login</button></form>',
|
196 |
-
'<nav class="flex justify-between p-4 bg-gray-100"><div class="font-bold">Logo</div><ul class="flex space-x-4"><li><a href="#" class="text-blue-500">Home</a></li><li><a href="#" class="text-blue-500">About</a></li></ul></nav>',
|
197 |
-
'<div class="text-center p-8"><h1 class="text-3xl mb-4">Hero Title</h1><p class="mb-6">Some description text here</p><button class="bg-red-500 text-white px-6 py-3">Get Started</button></div>',
|
198 |
-
'<div class="border p-6 max-w-sm"><h3 class="text-lg font-semibold mb-2">Basic Plan</h3><p class="text-2xl font-bold mb-4">$9/month</p><ul class="space-y-2 mb-6"><li>Feature 1</li><li>Feature 2</li></ul><button class="w-full bg-blue-500 text-white py-2">Choose Plan</button></div>',
|
199 |
],
|
200 |
css=custom_css,
|
201 |
)
|
202 |
|
203 |
if __name__ == "__main__":
|
204 |
-
demo.launch()
|
|
|
110 |
raise ValueError("No HTML content found in the response")
|
111 |
|
112 |
|
113 |
+
def redesign_html(html_input: str) -> str:
|
114 |
+
"""
|
115 |
+
Redesign HTML+TailwindCSS code with improved spacing, responsive design, and modern aesthetics.
|
116 |
+
|
117 |
+
This tool takes existing HTML with TailwindCSS classes and transforms it into a cleaner,
|
118 |
+
more modern version with better spacing, responsive design, and improved user experience.
|
119 |
+
|
120 |
+
IMPORTANT: This tool should only be used when users explicitly request to "redesign" HTML code.
|
121 |
+
Users must say "redesign" or similar intent for this tool to be activated.
|
122 |
+
|
123 |
+
Args:
|
124 |
+
html_input (str): The HTML code with TailwindCSS classes to be redesigned.
|
125 |
+
Can include React/Vue/Svelte/Angular syntax which will be preserved.
|
126 |
+
|
127 |
+
Returns:
|
128 |
+
str: The redesigned HTML code with improved TailwindCSS styling, preserving all
|
129 |
+
functionality, links, images, and framework-specific syntax.
|
130 |
+
|
131 |
+
Features:
|
132 |
+
- Preserves all functionality (links, images, forms, JavaScript)
|
133 |
+
- Maintains framework syntax (React JSX, Vue directives, etc.)
|
134 |
+
- Improves spacing and responsive design
|
135 |
+
- Preserves existing color schemes and fonts
|
136 |
+
- Adds proper flex-none for non-stretching elements
|
137 |
+
- Ensures mobile-first responsive design
|
138 |
+
- Supports dark mode when present in input
|
139 |
+
"""
|
140 |
+
|
141 |
# Check if HF_TOKEN is set
|
142 |
hf_token = os.getenv("HF_TOKEN")
|
143 |
if not hf_token:
|
|
|
150 |
"Content-Type": "application/json",
|
151 |
}
|
152 |
|
153 |
+
# Build messages with system prompt
|
154 |
+
messages = [
|
155 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
156 |
+
{"role": "user", "content": html_input}
|
157 |
+
]
|
|
|
|
|
158 |
|
159 |
data = {
|
160 |
"messages": messages,
|
|
|
173 |
# Extract HTML from the response
|
174 |
try:
|
175 |
html_content = extract_html_from_response(response_content)
|
176 |
+
return html_content
|
|
|
177 |
except ValueError as e:
|
178 |
return f"Error: {str(e)}. Response was: {response_content[:200]}..."
|
179 |
|
|
|
208 |
"""
|
209 |
|
210 |
# Create Gradio interface
|
211 |
+
demo = gr.Interface(
|
212 |
+
fn=redesign_html,
|
213 |
+
inputs=gr.Textbox(
|
214 |
+
label="HTML Input",
|
215 |
+
placeholder="Paste your HTML+TailwindCSS code here...",
|
216 |
+
lines=10,
|
217 |
+
value='<div class="p-4 border"><h1 class="text-xl">Welcome</h1><p>This is a basic card</p><button class="bg-blue-500 text-white px-4 py-2">Click me</button></div>'
|
218 |
+
),
|
219 |
+
outputs=gr.Code(language="html", label="Redesigned HTML"),
|
220 |
+
title="HTML+TailwindCSS Redesigner (MCP Server)",
|
221 |
+
description="""
|
222 |
+
**MCP Server Tool for HTML Redesigning**
|
223 |
+
|
224 |
+
This is an MCP (Model Context Protocol) server that provides HTML redesign capabilities to LLMs.
|
225 |
+
|
226 |
+
**IMPORTANT FOR LLM USAGE:** This tool should only be activated when users explicitly request to "redesign" HTML code.
|
227 |
+
Users must use the word "redesign" or similar intent (e.g., "improve the design", "make it look better") for this tool to be used.
|
228 |
+
|
229 |
+
**Features:**
|
230 |
+
- Improves HTML+TailwindCSS with better spacing and responsive design
|
231 |
+
- Preserves all functionality (links, images, forms, JavaScript)
|
232 |
+
- Maintains framework syntax (React, Vue, Svelte, Angular)
|
233 |
+
- Supports dark mode when present in input
|
234 |
+
- Mobile-first responsive design implementation
|
235 |
+
|
236 |
+
**Usage:** LLMs can use this tool when users ask to redesign HTML code by providing the HTML as input.
|
237 |
+
""",
|
238 |
examples=[
|
239 |
+
['<div class="p-4 border"><h1 class="text-xl">Welcome</h1><p>This is a basic card</p><button class="bg-blue-500 text-white px-4 py-2">Click me</button></div>'],
|
240 |
+
['<form class="space-y-4"><input type="email" placeholder="Email" class="border p-2 w-full"><input type="password" placeholder="Password" class="border p-2 w-full"><button type="submit" class="bg-green-500 text-white p-2">Login</button></form>'],
|
241 |
+
['<nav class="flex justify-between p-4 bg-gray-100"><div class="font-bold">Logo</div><ul class="flex space-x-4"><li><a href="#" class="text-blue-500">Home</a></li><li><a href="#" class="text-blue-500">About</a></li></ul></nav>'],
|
|
|
|
|
242 |
],
|
243 |
css=custom_css,
|
244 |
)
|
245 |
|
246 |
if __name__ == "__main__":
|
247 |
+
demo.launch(mcp_server=True)
|