Spaces:
Running
Running
update
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ DIVIDER = "======="
|
|
27 |
REPLACE_END = ">>>>>>> REPLACE"
|
28 |
|
29 |
# Configuration
|
30 |
-
SystemPrompt = """ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. MAKE IT RESPONSIVE USING
|
31 |
|
32 |
For website redesign tasks:
|
33 |
- Use the provided original HTML code as the starting point for redesign
|
@@ -47,7 +47,7 @@ Always respond with code that can be executed or rendered directly.
|
|
47 |
Always output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text."""
|
48 |
|
49 |
# System prompt with search capability
|
50 |
-
SystemPromptWithSearch = """ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. MAKE IT RESPONSIVE USING
|
51 |
|
52 |
You have access to real-time web search. When needed, use web search to find the latest information, best practices, or specific technologies.
|
53 |
|
@@ -1001,23 +1001,44 @@ This will help me create a better design for you."""
|
|
1001 |
content += chunk.choices[0].delta.content
|
1002 |
clean_code = remove_code_block(content)
|
1003 |
search_status = " (with web search)" if enable_search and tavily_client else ""
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1008 |
# Handle response based on whether this is a modification or new generation
|
1009 |
if has_existing_html:
|
1010 |
-
#
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
|
|
|
|
|
|
1015 |
# Update history with the cleaned HTML
|
1016 |
_history = messages_to_history(messages + [{
|
1017 |
'role': 'assistant',
|
1018 |
'content': clean_html
|
1019 |
}])
|
1020 |
-
|
1021 |
yield {
|
1022 |
code_output: clean_html,
|
1023 |
history: _history,
|
|
|
27 |
REPLACE_END = ">>>>>>> REPLACE"
|
28 |
|
29 |
# Configuration
|
30 |
+
SystemPrompt = """ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. MAKE IT RESPONSIVE USING MODERN CSS. Use as much as you can modern CSS for the styling, if you can't do something with modern CSS, then use custom CSS. Also, try to elaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE
|
31 |
|
32 |
For website redesign tasks:
|
33 |
- Use the provided original HTML code as the starting point for redesign
|
|
|
47 |
Always output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text."""
|
48 |
|
49 |
# System prompt with search capability
|
50 |
+
SystemPromptWithSearch = """ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. MAKE IT RESPONSIVE USING MODERN CSS. Use as much as you can modern CSS for the styling, if you can't do something with modern CSS, then use custom CSS. Also, try to elaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE
|
51 |
|
52 |
You have access to real-time web search. When needed, use web search to find the latest information, best practices, or specific technologies.
|
53 |
|
|
|
1001 |
content += chunk.choices[0].delta.content
|
1002 |
clean_code = remove_code_block(content)
|
1003 |
search_status = " (with web search)" if enable_search and tavily_client else ""
|
1004 |
+
if has_existing_html:
|
1005 |
+
# Fallback: If the model returns a full HTML file, use it directly
|
1006 |
+
if clean_code.strip().startswith("<!DOCTYPE html>") or clean_code.strip().startswith("<html"):
|
1007 |
+
yield {
|
1008 |
+
code_output: clean_code,
|
1009 |
+
history_output: history_to_chatbot_messages(_history),
|
1010 |
+
sandbox: send_to_sandbox(clean_code),
|
1011 |
+
}
|
1012 |
+
else:
|
1013 |
+
last_html = _history[-1][1] if _history else ""
|
1014 |
+
modified_html = apply_search_replace_changes(last_html, clean_code)
|
1015 |
+
clean_html = remove_code_block(modified_html)
|
1016 |
+
yield {
|
1017 |
+
code_output: clean_html,
|
1018 |
+
history_output: history_to_chatbot_messages(_history),
|
1019 |
+
sandbox: send_to_sandbox(clean_html),
|
1020 |
+
}
|
1021 |
+
else:
|
1022 |
+
yield {
|
1023 |
+
code_output: clean_code,
|
1024 |
+
history_output: history_to_chatbot_messages(_history),
|
1025 |
+
sandbox: send_to_sandbox(clean_code),
|
1026 |
+
}
|
1027 |
# Handle response based on whether this is a modification or new generation
|
1028 |
if has_existing_html:
|
1029 |
+
# Fallback: If the model returns a full HTML file, use it directly
|
1030 |
+
final_code = remove_code_block(content)
|
1031 |
+
if final_code.strip().startswith("<!DOCTYPE html>") or final_code.strip().startswith("<html"):
|
1032 |
+
clean_html = final_code
|
1033 |
+
else:
|
1034 |
+
last_html = _history[-1][1] if _history else ""
|
1035 |
+
modified_html = apply_search_replace_changes(last_html, final_code)
|
1036 |
+
clean_html = remove_code_block(modified_html)
|
1037 |
# Update history with the cleaned HTML
|
1038 |
_history = messages_to_history(messages + [{
|
1039 |
'role': 'assistant',
|
1040 |
'content': clean_html
|
1041 |
}])
|
|
|
1042 |
yield {
|
1043 |
code_output: clean_html,
|
1044 |
history: _history,
|