Spaces:
Running
Running
gradio followup
Browse files
app.py
CHANGED
|
@@ -1722,6 +1722,51 @@ IMPORTANT: Always ensure "Built with anycoder" appears as clickable text in the
|
|
| 1722 |
|
| 1723 |
CRITICAL: For imported spaces that lack anycoder attribution, you MUST add it as part of your modifications. Add it to the header/navigation area as clickable text linking to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1725 |
# Follow-up system prompt for modifying existing transformers.js applications
|
| 1726 |
TransformersJSFollowUpSystemPrompt = f"""You are an expert web developer modifying an existing transformers.js application.
|
| 1727 |
The user wants to apply changes based on their request.
|
|
@@ -5934,6 +5979,8 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 5934 |
# Use follow-up prompt for modifying existing content
|
| 5935 |
if language == "transformers.js":
|
| 5936 |
system_prompt = TransformersJSFollowUpSystemPrompt
|
|
|
|
|
|
|
| 5937 |
elif language == "svelte":
|
| 5938 |
system_prompt = FollowUpSystemPrompt # Use generic follow-up for Svelte
|
| 5939 |
else:
|
|
@@ -6474,6 +6521,34 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 6474 |
history: _history,
|
| 6475 |
history_output: history_to_chatbot_messages(_history),
|
| 6476 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6477 |
elif has_existing_content:
|
| 6478 |
# Handle modification of existing content
|
| 6479 |
final_code = remove_code_block(content)
|
|
|
|
| 1722 |
|
| 1723 |
CRITICAL: For imported spaces that lack anycoder attribution, you MUST add it as part of your modifications. Add it to the header/navigation area as clickable text linking to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1724 |
|
| 1725 |
+
# Follow-up system prompt for modifying existing Gradio applications
|
| 1726 |
+
GradioFollowUpSystemPrompt = """You are an expert Gradio developer modifying an existing Gradio application.
|
| 1727 |
+
The user wants to apply changes based on their request.
|
| 1728 |
+
|
| 1729 |
+
CRITICAL: You MUST maintain the original multi-file structure when making modifications.
|
| 1730 |
+
Do NOT use SEARCH/REPLACE blocks. Instead, output the complete modified files using the same format as the original generation.
|
| 1731 |
+
|
| 1732 |
+
**Output Format for Modified Gradio Apps:**
|
| 1733 |
+
When modifying multi-file Gradio applications, use this exact format:
|
| 1734 |
+
|
| 1735 |
+
```
|
| 1736 |
+
=== app.py ===
|
| 1737 |
+
[complete modified app.py content]
|
| 1738 |
+
|
| 1739 |
+
=== utils.py ===
|
| 1740 |
+
[complete modified utils.py content - only if it exists and needs changes]
|
| 1741 |
+
|
| 1742 |
+
=== requirements.txt ===
|
| 1743 |
+
[complete modified requirements.txt content]
|
| 1744 |
+
```
|
| 1745 |
+
|
| 1746 |
+
**File Modification Guidelines:**
|
| 1747 |
+
- Only output files that actually need changes
|
| 1748 |
+
- If a file doesn't need modification, don't include it in the output
|
| 1749 |
+
- Maintain the exact same file structure as the original
|
| 1750 |
+
- Preserve all existing functionality unless specifically asked to change it
|
| 1751 |
+
- Keep all imports, dependencies, and configurations intact unless modification is requested
|
| 1752 |
+
|
| 1753 |
+
**Common Modification Scenarios:**
|
| 1754 |
+
- Adding new features β Modify app.py and possibly utils.py
|
| 1755 |
+
- Fixing bugs β Modify the relevant file (usually app.py)
|
| 1756 |
+
- Adding dependencies β Modify requirements.txt
|
| 1757 |
+
- UI improvements β Modify app.py
|
| 1758 |
+
- Performance optimizations β Modify app.py and/or utils.py
|
| 1759 |
+
|
| 1760 |
+
**ZeroGPU and Performance:**
|
| 1761 |
+
- Maintain all existing @spaces.GPU decorators
|
| 1762 |
+
- Keep AoT compilation if present
|
| 1763 |
+
- Preserve all performance optimizations
|
| 1764 |
+
- Add ZeroGPU decorators for new GPU-dependent functions
|
| 1765 |
+
|
| 1766 |
+
IMPORTANT: Always ensure "Built with anycoder" appears as clickable text in the header/top section linking to https://huggingface.co/spaces/akhaliq/anycoder - if it's missing from the existing code, add it; if it exists, preserve it.
|
| 1767 |
+
|
| 1768 |
+
CRITICAL: For imported spaces that lack anycoder attribution, you MUST add it as part of your modifications. Add it to the header/navigation area as clickable text linking to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1769 |
+
|
| 1770 |
# Follow-up system prompt for modifying existing transformers.js applications
|
| 1771 |
TransformersJSFollowUpSystemPrompt = f"""You are an expert web developer modifying an existing transformers.js application.
|
| 1772 |
The user wants to apply changes based on their request.
|
|
|
|
| 5979 |
# Use follow-up prompt for modifying existing content
|
| 5980 |
if language == "transformers.js":
|
| 5981 |
system_prompt = TransformersJSFollowUpSystemPrompt
|
| 5982 |
+
elif language == "gradio":
|
| 5983 |
+
system_prompt = GradioFollowUpSystemPrompt
|
| 5984 |
elif language == "svelte":
|
| 5985 |
system_prompt = FollowUpSystemPrompt # Use generic follow-up for Svelte
|
| 5986 |
else:
|
|
|
|
| 6521 |
history: _history,
|
| 6522 |
history_output: history_to_chatbot_messages(_history),
|
| 6523 |
}
|
| 6524 |
+
elif language == "gradio":
|
| 6525 |
+
# Handle Gradio output - check if it's multi-file format or single file
|
| 6526 |
+
if ('=== app.py ===' in content or '=== requirements.txt ===' in content):
|
| 6527 |
+
# Model returned complete multi-file Gradio output (new generation or followup with multi-file format)
|
| 6528 |
+
_history.append([query, content])
|
| 6529 |
+
yield {
|
| 6530 |
+
code_output: content,
|
| 6531 |
+
history: _history,
|
| 6532 |
+
history_output: history_to_chatbot_messages(_history),
|
| 6533 |
+
}
|
| 6534 |
+
elif has_existing_content:
|
| 6535 |
+
# Model returned search/replace changes for Gradio - apply them
|
| 6536 |
+
last_content = _history[-1][1] if _history and len(_history[-1]) > 1 else ""
|
| 6537 |
+
modified_content = apply_search_replace_changes(last_content, content)
|
| 6538 |
+
_history.append([query, modified_content])
|
| 6539 |
+
yield {
|
| 6540 |
+
code_output: modified_content,
|
| 6541 |
+
history: _history,
|
| 6542 |
+
history_output: history_to_chatbot_messages(_history),
|
| 6543 |
+
}
|
| 6544 |
+
else:
|
| 6545 |
+
# Fallback - treat as single file Gradio app
|
| 6546 |
+
_history.append([query, content])
|
| 6547 |
+
yield {
|
| 6548 |
+
code_output: content,
|
| 6549 |
+
history: _history,
|
| 6550 |
+
history_output: history_to_chatbot_messages(_history),
|
| 6551 |
+
}
|
| 6552 |
elif has_existing_content:
|
| 6553 |
# Handle modification of existing content
|
| 6554 |
final_code = remove_code_block(content)
|