Spaces:
Sleeping
Sleeping
update react parser
Browse filesFiles changed (2)
18 unmodified lines192021222324747 unmodified lines77277377477577677777877918 unmodified linesparse_html_code,parse_python_requirements,parse_multi_file_python_output,strip_tool_call_markers,remove_code_block,extract_import_statements,747 unmodified linesuse_individual_uploads = True # Streamlit uses individual file uploadselif language == "react":# Parse React output to get all files (uses same multi-file format as Python)files = parse_multi_file_python_output(code)if not files:return False, "Error: Could not parse React output", None18 unmodified lines19202122232425747 unmodified lines77377477577677777877978018 unmodified linesparse_html_code,parse_python_requirements,parse_multi_file_python_output,parse_react_output,strip_tool_call_markers,remove_code_block,extract_import_statements,747 unmodified linesuse_individual_uploads = True # Streamlit uses individual file uploadselif language == "react":# Parse React output to get all files (uses === filename === markers)files = parse_react_output(code)if not files:return False, "Error: Could not parse React output", None
301 unmodified lines302303304305306307301 unmodified linesreturn list(set(import_statements)) # Remove duplicatesdef generate_requirements_txt_with_llm(import_statements):"""Generate requirements.txt content using LLM based on import statements."""if not import_statements:301 unmodified lines302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369301 unmodified linesreturn list(set(import_statements)) # Remove duplicatesdef parse_multipage_html_output(text: str) -> Dict[str, str]:"""Parse multi-page HTML output formatted as repeated "=== filename ===" sections.Returns a mapping of filename → file content. Supports nested paths like assets/css/styles.css.If HTML content appears before the first === marker, it's treated as index.html."""if not text:return {}# First, strip any markdown fencescleaned = remove_code_block(text)files: Dict[str, str] = {}# Check if there's content before the first === markerfirst_marker_match = re.search(r"^===\s*([^=\n]+?)\s*===", cleaned, re.MULTILINE)if first_marker_match:# There's content before the first markerfirst_marker_pos = first_marker_match.start()if first_marker_pos > 0:leading_content = cleaned[:first_marker_pos].strip()# Check if it looks like HTML contentif leading_content and ('<!DOCTYPE' in leading_content or '<html' in leading_content or leading_content.startswith('<')):files['index.html'] = leading_content# Now parse the rest with === markersremaining_text = cleaned[first_marker_pos:] if first_marker_pos > 0 else cleanedpattern = re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", re.MULTILINE)for m in pattern.finditer(remaining_text):name = m.group(1).strip()content = m.group(2).strip()# Remove accidental trailing fences if presentcontent = re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)files[name] = contentelse:# No === markers found, try standard pattern matchingpattern = re.compile(r"^===\s*([^=\n]+?)\s*===\s*\n([\s\S]*?)(?=\n===\s*[^=\n]+?\s*===|\Z)", re.MULTILINE)for m in pattern.finditer(cleaned):name = m.group(1).strip()content = m.group(2).strip()# Remove accidental trailing fences if presentcontent = re.sub(r"^```\w*\s*\n|\n```\s*$", "", content)files[name] = contentreturn filesdef parse_react_output(text: str) -> Dict[str, str]:"""Parse React/Next.js output to extract individual files.Supports multi-file sections using === filename === sections."""if not text:return {}# Use the generic multipage parsertry:files = parse_multipage_html_output(text) or {}except Exception:files = {}return files if isinstance(files, dict) and files else {}def generate_requirements_txt_with_llm(import_statements):"""Generate requirements.txt content using LLM based on import statements."""if not import_statements:
backend_deploy.py+3-2
backend_parsers.py+62