fix issue
Browse filesFiles changed (2)
110 unmodified lines111112113114115116117118119120121122123124125126127128129130131132133150 unmodified lines284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315110 unmodified lineslast_assistant_msg = ""if _history and len(_history[-1]) > 1:last_assistant_msg = _history[-1][1]# Check for various content types that indicate an existing projectif ('<!DOCTYPE html>' in last_assistant_msg or'<html' in last_assistant_msg or'import gradio' in last_assistant_msg or'import streamlit' in last_assistant_msg or'def ' in last_assistant_msg and 'app' in last_assistant_msg or'IMPORTED PROJECT FROM HUGGING FACE SPACE' in last_assistant_msg or'InferenceClient' in last_assistant_msg or # Inference provider code'from huggingface_hub import' in last_assistant_msg or # Inference provider code'from transformers import' in last_assistant_msg or # Transformers code'from diffusers import' in last_assistant_msg or # Diffusers code'=== index.html ===' in last_assistant_msg or'=== index.js ===' in last_assistant_msg or'=== style.css ===' in last_assistant_msg or'=== app.py ===' in last_assistant_msg or'=== requirements.txt ===' in last_assistant_msg):has_existing_content = True# If this is a modification request, try to apply search/replace firstif has_existing_content and query.strip():150 unmodified linesmessages = history_to_messages(_history, system_prompt)# Check if user has imported inference provider or model code and enhance the queryhas_imported_model_code = Falseimported_model_info = ""if _history:for user_msg, assistant_msg in _history:# Check if this is an imported modelif "Imported model:" in user_msg or "Imported inference provider code" in assistant_msg:has_imported_model_code = True# Extract the model code from assistant messageif "InferenceClient" in assistant_msg or "from huggingface_hub import" in assistant_msg:# Provide specific instructions based on the type of app being createdif language == "gradio":imported_model_info = f"\n\n**CRITICAL INSTRUCTION: The user has imported HuggingFace Inference Provider code in the previous message. You MUST use this code as the backend for the Gradio application. Create a Gradio interface that:**\n1. Uses the InferenceClient from the imported code\n2. Creates a chatbot interface with gr.ChatInterface or gr.Blocks\n3. Implements a function that calls the model using client.chat.completions.create()\n4. Handles streaming responses properly\n5. Includes proper error handling\n\n**DO NOT ignore the imported code - integrate it into your Gradio app!**"else:imported_model_info = f"\n\n**IMPORTANT: The user has already imported model inference code in the conversation history. When creating the {language} application, USE the imported inference code as the backend. Integrate it properly into your application.**"breakelif "from transformers import" in assistant_msg or "from diffusers import" in assistant_msg:if language == "gradio":imported_model_info = f"\n\n**CRITICAL INSTRUCTION: The user has imported transformers/diffusers model code in the previous message. You MUST use this code as the backend for the Gradio application. Create a Gradio interface that:**\n1. Uses the model loading code from the imported code\n2. Creates an appropriate interface based on the model type\n3. Implements inference functions that use the imported model\n4. Includes proper error handling\n\n**DO NOT ignore the imported code - integrate it into your Gradio app!**"else:imported_model_info = f"\n\n**IMPORTANT: The user has already imported transformers/diffusers model code in the conversation history. When creating the {language} application, USE the imported model code as the backend. Integrate it properly into your application.**"break# Use the original query, enhanced with context about imported code if applicableenhanced_query = query + imported_model_info# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClientif _current_model["id"] == "zai-org/GLM-4.5":110 unmodified lines111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140150 unmodified lines291292293294295296297298110 unmodified lineslast_assistant_msg = ""if _history and len(_history[-1]) > 1:last_assistant_msg = _history[-1][1]# Check if this is imported model code (should NOT be treated as existing content to modify)is_imported_model_code = ("Imported model:" in _history[-1][0] or"Imported inference provider code" in last_assistant_msg or"Imported transformers/diffusers code" in last_assistant_msg or"Switched code type" in _history[-1][0])# Only treat as existing content if it's NOT imported model codeif not is_imported_model_code:# Check for various content types that indicate an existing projectif ('<!DOCTYPE html>' in last_assistant_msg or'<html' in last_assistant_msg or'import gradio' in last_assistant_msg or'import streamlit' in last_assistant_msg or'def ' in last_assistant_msg and 'app' in last_assistant_msg or'IMPORTED PROJECT FROM HUGGING FACE SPACE' in last_assistant_msg or'=== index.html ===' in last_assistant_msg or'=== index.js ===' in last_assistant_msg or'=== style.css ===' in last_assistant_msg or'=== app.py ===' in last_assistant_msg or'=== requirements.txt ===' in last_assistant_msg):has_existing_content = True# If this is a modification request, try to apply search/replace firstif has_existing_content and query.strip():150 unmodified linesmessages = history_to_messages(_history, system_prompt)# Use the original query without any enhancements - let the system prompt handle everythingenhanced_query = query# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClientif _current_model["id"] == "zai-org/GLM-4.5":
382 unmodified lines383384385386387388897 unmodified lines12861287128812891290129112921293382 unmodified lines- Generate ONLY the requested code files and requirements.txt- No explanatory text outside the code blocks## Multi-File Application StructureWhen creating complex Gradio applications, organize your code into multiple files for better maintainability:897 unmodified linessearch_prompt += fastrtc_section# Update the prompts in the prompts moduleprompts.GRADIO_SYSTEM_PROMPT = base_prompt + docs_content + "\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.\n\nIMPORTANT: Always include \"Built with anycoder\" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"prompts.GRADIO_SYSTEM_PROMPT_WITH_SEARCH = search_prompt + docs_content + "\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.\n\nIMPORTANT: Always include \"Built with anycoder\" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"def update_json_system_prompts():"""Update the global JSON system prompts with latest ComfyUI documentation"""382 unmodified lines383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448897 unmodified lines13461347134813491350135113521353135413551356135713581359382 unmodified lines- Generate ONLY the requested code files and requirements.txt- No explanatory text outside the code blocks## π― Working with Imported Model Code**CRITICAL: If the user has imported model code in the conversation history (InferenceClient, transformers, diffusers), you MUST integrate it into your Gradio application!****For InferenceClient Code (HuggingFace Inference API):**- DO NOT just copy the standalone inference code- Create a complete Gradio application that wraps the inference code- Use `gr.ChatInterface()` for chat models or appropriate interface for other tasks- Extract the model name from the imported code- Implement proper streaming if the model supports it- Handle conversation history correctly**Example Structure for Chatbot:**```pythonimport gradio as grimport osfrom huggingface_hub import InferenceClient# Use the InferenceClient configuration from imported codeclient = InferenceClient(api_key=os.environ["HF_TOKEN"])def respond(message, history):# Build messages from historymessages = [{"role": "system", "content": "You are a helpful assistant."}]for user_msg, assistant_msg in history:messages.append({"role": "user", "content": user_msg})messages.append({"role": "assistant", "content": assistant_msg})messages.append({"role": "user", "content": message})# Call the model (use model name from imported code)response = ""for chunk in client.chat.completions.create(model="MODEL_NAME_FROM_IMPORTED_CODE",messages=messages,stream=True,max_tokens=1024,):if chunk.choices[0].delta.content:response += chunk.choices[0].delta.contentyield responsedemo = gr.ChatInterface(respond, title="Chatbot", description="Chat with the model")demo.launch()```**For Transformers/Diffusers Code:**- Extract model loading and inference logic- Wrap it in appropriate Gradio interface- For chat models: use gr.ChatInterface- For image generation: use gr.Interface with image output- For other tasks: choose appropriate interface type- Include proper error handling and loading states**Key Requirements:**1. β ALWAYS create a complete Gradio application, not just inference code2. β Extract model configuration from imported code3. β Use appropriate Gradio interface for the task4. β Include demo.launch() at the end5. β Add requirements.txt with necessary dependencies## Multi-File Application StructureWhen creating complex Gradio applications, organize your code into multiple files for better maintainability:897 unmodified linessearch_prompt += fastrtc_section# Update the prompts in the prompts modulefinal_instructions = """\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.π BEFORE GENERATING: Review the conversation history carefully. If the user has imported any model code (InferenceClient, transformers, diffusers), you MUST integrate that code into your Gradio application. Do not generate standalone inference code - create a complete Gradio app that wraps the imported model functionality.IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""prompts.GRADIO_SYSTEM_PROMPT = base_prompt + docs_content + final_instructionsprompts.GRADIO_SYSTEM_PROMPT_WITH_SEARCH = search_prompt + docs_content + final_instructionsdef update_json_system_prompts():"""Update the global JSON system prompts with latest ComfyUI documentation"""
anycoder_app/deploy.py+26-43
anycoder_app/docs_manager.py+68-2