update
Browse filesFiles changed (2)
- backend_deploy.py+38-21
- backend_parsers.py+11-3
287 unmodified lines288289290291292293294291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325296297298299300301302303304305306307326327328309310311312313329330331332333287 unmodified lines return json_content
def parse_transformers_js_output(code: str) -> Dict[str, str]: """Parse transformers.js output into separate files (index.html, index.js, style.css) Uses comprehensive parsing patterns to handle various LLM output formats.# Note: parse_transformers_js_output, parse_python_requirements, strip_tool_call_markers,# remove_code_block, extract_import_statements, generate_requirements_txt_with_llm,# and parse_multi_file_python_output are now imported from backend_parsers.py
def is_streamlit_code(code: str) -> bool: """Check if code is Streamlit""" return 'import streamlit' in code or 'streamlit.run' in code
def is_gradio_code(code: str) -> bool: """Check if code is Gradio""" return 'import gradio' in code or 'gr.' in code
def detect_sdk_from_code(code: str, language: str) -> str: """Detect the appropriate SDK from code and language""" if language == "html": return "static" elif language == "transformers.js": return "static" elif language == "comfyui": return "static" elif language == "react": return "docker" elif language == "streamlit" or is_streamlit_code(code): return "docker" elif language == "gradio" or is_gradio_code(code): return "gradio" else: return "gradio" # Default
def add_anycoder_tag_to_readme(api, repo_id: str, app_port: Optional[int] = None) -> None: """ files = { 'index.html': '', 'index.js': '', 'style.css': '' } # Multiple patterns to match the three code blocks with different variations html_patterns = [ r'```html\s*\n([\s\S]*?)(?:```|\Z)', r'```htm\s*\n([\s\S]*?)(?:```|\Z)', r'```\s*(?:index\.html|html)\s*\n([\s\S]*?)(?:```|\Z)' ] Download existing README, add anycoder tag and app_port if needed, and upload back. Preserves all existing README content and frontmatter. js_patterns = [ r'```javascript\s*\n([\s\S]*?)(?:```|\Z)', r'```js\s*\n([\s\S]*?)(?:```|\Z)', r'```\s*(?:index\.js|javascript|js)\s*\n([\s\S]*?)(?:```|\Z)' ] Args: api: HuggingFace API client css_patterns = [ r'```css\s*\n([\s\S]*?)(?:```|\Z)',14 unmodified lines151617181920212223242526272829303198 unmodified lines13013113213312812913013413513613713813914014114 unmodified lines Uses comprehensive parsing patterns to handle various LLM output formats. Updated to use transformers.js v3.8.0 CDN. """ print(f"[Parser] Received code length: {len(code)} characters") print(f"[Parser] First 200 chars: {code[:200]}") # Auto-fix: If code doesn't start with === index.html ===, add it code_stripped = code.strip() if not code_stripped.startswith('==='): print("[Parser] Auto-fixing: Adding missing === index.html === marker") code = '=== index.html ===\n' + code code_stripped = code.strip() else: print("[Parser] Code starts with === marker, proceeding normally") # Check if code starts with HTML instead of markers (common LLM mistake) if code_stripped.startswith('<!DOCTYPE') or code_stripped.startswith('<html'):98 unmodified lines # Fallback: support === index.html === format if any file is missing if not (files['index.html'] and files['index.js'] and files['style.css']): # Use regex to extract sections - match === markers with optional whitespace and newlines # Made [\r\n]+ optional with * instead of + to handle cases where content follows immediately html_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]+([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE) js_fallback = re.search(r'===\s*index\.js\s*===\s*[\r\n]+([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE) css_fallback = re.search(r'===\s*style\.css\s*===\s*[\r\n]+([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE) html_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]*([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE) js_fallback = re.search(r'===\s*index\.js\s*===\s*[\r\n]*([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE) css_fallback = re.search(r'===\s*style\.css\s*===\s*[\r\n]*([\s\S]+?)(?=\n===|$)', code, re.IGNORECASE) print(f"[Parser] Fallback extraction - HTML found: {bool(html_fallback)}, JS found: {bool(js_fallback)}, CSS found: {bool(css_fallback)}") if html_fallback: content = html_fallback.group(1).strip()backend_deploy.py+38-21
backend_parsers.py+11-3