Spaces:
Running
Running
followup prompts
Browse files
app.py
CHANGED
|
@@ -228,10 +228,22 @@ GENERIC_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert {language} developer. Y
|
|
| 228 |
Write clean, idiomatic, and runnable {language} code for the user's request. If possible, include comments and best practices. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. If the user provides a file or other context, use it as a reference. If the code is for a script or app, make it as self-contained as possible. Do NOT add the language name at the top of the code output."""
|
| 229 |
|
| 230 |
# Follow-up system prompt for modifying existing HTML files
|
| 231 |
-
FollowUpSystemPrompt = f"""You are an expert web developer modifying an existing
|
| 232 |
The user wants to apply changes based on their request.
|
| 233 |
You MUST output ONLY the changes required using the following SEARCH/REPLACE block format. Do NOT output the entire file.
|
| 234 |
Explain the changes briefly *before* the blocks if necessary, but the code changes THEMSELVES MUST be within the blocks.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
Format Rules:
|
| 236 |
1. Start with {SEARCH_START}
|
| 237 |
2. Provide the exact lines from the current code that need to be replaced.
|
|
@@ -242,6 +254,8 @@ Format Rules:
|
|
| 242 |
7. To insert code, use an empty SEARCH block (only {SEARCH_START} and {DIVIDER} on their lines) if inserting at the very beginning, otherwise provide the line *before* the insertion point in the SEARCH block and include that line plus the new lines in the REPLACE block.
|
| 243 |
8. To delete code, provide the lines to delete in the SEARCH block and leave the REPLACE block empty (only {DIVIDER} and {REPLACE_END} on their lines).
|
| 244 |
9. IMPORTANT: The SEARCH block must *exactly* match the current code, including indentation and whitespace.
|
|
|
|
|
|
|
| 245 |
Example Modifying Code:
|
| 246 |
```
|
| 247 |
Some explanation...
|
|
@@ -257,6 +271,21 @@ Some explanation...
|
|
| 257 |
</body>
|
| 258 |
{REPLACE_END}
|
| 259 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
Example Deleting Code:
|
| 261 |
```
|
| 262 |
Removing the paragraph...
|
|
@@ -272,6 +301,12 @@ The user wants to apply changes based on their request.
|
|
| 272 |
You MUST output ONLY the changes required using the following SEARCH/REPLACE block format. Do NOT output the entire file.
|
| 273 |
Explain the changes briefly *before* the blocks if necessary, but the code changes THEMSELVES MUST be within the blocks.
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
The transformers.js application consists of three files: index.html, index.js, and style.css.
|
| 276 |
When making changes, specify which file you're modifying by starting your search/replace blocks with the file name.
|
| 277 |
|
|
@@ -289,6 +324,7 @@ Format Rules:
|
|
| 289 |
Example Modifying HTML:
|
| 290 |
```
|
| 291 |
Changing the title in index.html...
|
|
|
|
| 292 |
{SEARCH_START}
|
| 293 |
<title>Old Title</title>
|
| 294 |
{DIVIDER}
|
|
@@ -299,6 +335,7 @@ Changing the title in index.html...
|
|
| 299 |
Example Modifying JavaScript:
|
| 300 |
```
|
| 301 |
Adding a new function to index.js...
|
|
|
|
| 302 |
{SEARCH_START}
|
| 303 |
// Existing code
|
| 304 |
{DIVIDER}
|
|
@@ -313,6 +350,7 @@ function newFunction() {{
|
|
| 313 |
Example Modifying CSS:
|
| 314 |
```
|
| 315 |
Changing background color in style.css...
|
|
|
|
| 316 |
{SEARCH_START}
|
| 317 |
body {{
|
| 318 |
background-color: white;
|
|
@@ -322,6 +360,17 @@ body {{
|
|
| 322 |
background-color: #f0f0f0;
|
| 323 |
}}
|
| 324 |
{REPLACE_END}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
```"""
|
| 326 |
|
| 327 |
# Available models
|
|
|
|
| 228 |
Write clean, idiomatic, and runnable {language} code for the user's request. If possible, include comments and best practices. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. If the user provides a file or other context, use it as a reference. If the code is for a script or app, make it as self-contained as possible. Do NOT add the language name at the top of the code output."""
|
| 229 |
|
| 230 |
# Follow-up system prompt for modifying existing HTML files
|
| 231 |
+
FollowUpSystemPrompt = f"""You are an expert web developer modifying an existing project.
|
| 232 |
The user wants to apply changes based on their request.
|
| 233 |
You MUST output ONLY the changes required using the following SEARCH/REPLACE block format. Do NOT output the entire file.
|
| 234 |
Explain the changes briefly *before* the blocks if necessary, but the code changes THEMSELVES MUST be within the blocks.
|
| 235 |
+
|
| 236 |
+
IMPORTANT: When the user reports an ERROR MESSAGE, analyze it carefully to determine which file needs fixing:
|
| 237 |
+
- ImportError/ModuleNotFoundError β Fix requirements.txt by adding missing packages
|
| 238 |
+
- Syntax errors in Python code β Fix app.py or the main Python file
|
| 239 |
+
- HTML/CSS/JavaScript errors β Fix the respective HTML/CSS/JS files
|
| 240 |
+
- Configuration errors β Fix config files, Docker files, etc.
|
| 241 |
+
|
| 242 |
+
For Python applications (Gradio/Streamlit), the project structure typically includes:
|
| 243 |
+
- app.py (main application file)
|
| 244 |
+
- requirements.txt (dependencies)
|
| 245 |
+
- Other supporting files as needed
|
| 246 |
+
|
| 247 |
Format Rules:
|
| 248 |
1. Start with {SEARCH_START}
|
| 249 |
2. Provide the exact lines from the current code that need to be replaced.
|
|
|
|
| 254 |
7. To insert code, use an empty SEARCH block (only {SEARCH_START} and {DIVIDER} on their lines) if inserting at the very beginning, otherwise provide the line *before* the insertion point in the SEARCH block and include that line plus the new lines in the REPLACE block.
|
| 255 |
8. To delete code, provide the lines to delete in the SEARCH block and leave the REPLACE block empty (only {DIVIDER} and {REPLACE_END} on their lines).
|
| 256 |
9. IMPORTANT: The SEARCH block must *exactly* match the current code, including indentation and whitespace.
|
| 257 |
+
10. For multi-file projects, specify which file you're modifying by starting with the filename before the search/replace block.
|
| 258 |
+
|
| 259 |
Example Modifying Code:
|
| 260 |
```
|
| 261 |
Some explanation...
|
|
|
|
| 271 |
</body>
|
| 272 |
{REPLACE_END}
|
| 273 |
```
|
| 274 |
+
|
| 275 |
+
Example Fixing Dependencies (requirements.txt):
|
| 276 |
+
```
|
| 277 |
+
Adding missing dependency to fix ImportError...
|
| 278 |
+
=== requirements.txt ===
|
| 279 |
+
{SEARCH_START}
|
| 280 |
+
gradio
|
| 281 |
+
streamlit
|
| 282 |
+
{DIVIDER}
|
| 283 |
+
gradio
|
| 284 |
+
streamlit
|
| 285 |
+
mistral-common
|
| 286 |
+
{REPLACE_END}
|
| 287 |
+
```
|
| 288 |
+
|
| 289 |
Example Deleting Code:
|
| 290 |
```
|
| 291 |
Removing the paragraph...
|
|
|
|
| 301 |
You MUST output ONLY the changes required using the following SEARCH/REPLACE block format. Do NOT output the entire file.
|
| 302 |
Explain the changes briefly *before* the blocks if necessary, but the code changes THEMSELVES MUST be within the blocks.
|
| 303 |
|
| 304 |
+
IMPORTANT: When the user reports an ERROR MESSAGE, analyze it carefully to determine which file needs fixing:
|
| 305 |
+
- JavaScript errors/module loading issues β Fix index.js
|
| 306 |
+
- HTML rendering/DOM issues β Fix index.html
|
| 307 |
+
- Styling/visual issues β Fix style.css
|
| 308 |
+
- CDN/library loading errors β Fix script tags in index.html
|
| 309 |
+
|
| 310 |
The transformers.js application consists of three files: index.html, index.js, and style.css.
|
| 311 |
When making changes, specify which file you're modifying by starting your search/replace blocks with the file name.
|
| 312 |
|
|
|
|
| 324 |
Example Modifying HTML:
|
| 325 |
```
|
| 326 |
Changing the title in index.html...
|
| 327 |
+
=== index.html ===
|
| 328 |
{SEARCH_START}
|
| 329 |
<title>Old Title</title>
|
| 330 |
{DIVIDER}
|
|
|
|
| 335 |
Example Modifying JavaScript:
|
| 336 |
```
|
| 337 |
Adding a new function to index.js...
|
| 338 |
+
=== index.js ===
|
| 339 |
{SEARCH_START}
|
| 340 |
// Existing code
|
| 341 |
{DIVIDER}
|
|
|
|
| 350 |
Example Modifying CSS:
|
| 351 |
```
|
| 352 |
Changing background color in style.css...
|
| 353 |
+
=== style.css ===
|
| 354 |
{SEARCH_START}
|
| 355 |
body {{
|
| 356 |
background-color: white;
|
|
|
|
| 360 |
background-color: #f0f0f0;
|
| 361 |
}}
|
| 362 |
{REPLACE_END}
|
| 363 |
+
```
|
| 364 |
+
|
| 365 |
+
Example Fixing Library Loading Error:
|
| 366 |
+
```
|
| 367 |
+
Fixing transformers.js CDN loading error...
|
| 368 |
+
=== index.html ===
|
| 369 |
+
{SEARCH_START}
|
| 370 |
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0"></script>
|
| 371 |
+
{DIVIDER}
|
| 372 |
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2"></script>
|
| 373 |
+
{REPLACE_END}
|
| 374 |
```"""
|
| 375 |
|
| 376 |
# Available models
|