fix requirements.txt issue
Browse files482 unmodified lines483484485486487488489490491492493494495496497498499500501502503504505298 unmodified lines804805806807808809810811812813814815816817818819820821822823824825826672 unmodified lines14991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521291 unmodified lines181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418353781 unmodified lines561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568911 unmodified lines570157025703570457055706570757085709571057117 unmodified lines5719572057215582572257235724572557265727572857292 unmodified lines57325733573455915735573657375738573957405741574234 unmodified lines577757785779563257805781578257835784578557865787578857891167 unmodified lines69576958695969606961696269636964696569666967696869696809697069716972697310 unmodified lines69846985698669876988698969906991699269936827682868296830683168326833683468356994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701968377020702170227023482 unmodified lines- Include supporting packages (accelerate, torch, tokenizers, etc.) when using ML libraries- Your requirements.txt should ensure the application works smoothly in production
**🚨 CRITICAL: requirements.txt Formatting Rules**- Output ONLY plain text package names, one per line- Do NOT use markdown formatting (no ```, no bold, no headings, no lists with * or -)- Do NOT add explanatory text or descriptions- Do NOT wrap in code blocks- Just raw package names as they would appear in a real requirements.txt file- Example of CORRECT format: gradio torch transformers- Example of INCORRECT format (DO NOT DO THIS): ``` gradio # For web interface **Core dependencies:** - torch ```
**Single vs Multi-File Decision:**- Use single file for simple applications (< 100 lines) - but still generate requirements.txt if dependencies exist- Use multi-file structure for complex applications with:298 unmodified lines[dependencies]```
**🚨 CRITICAL: requirements.txt Formatting Rules**- Output ONLY plain text package names, one per line- Do NOT use markdown formatting (no ```, no bold, no headings, no lists with * or -)- Do NOT add explanatory text or descriptions- Do NOT wrap in code blocks- Just raw package names as they would appear in a real requirements.txt file- Example of CORRECT format: gradio torch transformers- Example of INCORRECT format (DO NOT DO THIS): ``` gradio # For web interface **Core dependencies:** - torch ```
**Single vs Multi-File Decision:**- Use single file for simple applications (< 100 lines) - but still generate requirements.txt if dependencies exist- Use multi-file structure for complex applications with:672 unmodified lines[dependencies]```
**🚨 CRITICAL: requirements.txt Formatting Rules**- Output ONLY plain text package names, one per line- Do NOT use markdown formatting (no ```, no bold, no headings, no lists with * or -)- Do NOT add explanatory text or descriptions- Do NOT wrap in code blocks- Just raw package names as they would appear in a real requirements.txt file- Example of CORRECT format: streamlit pandas numpy- Example of INCORRECT format (DO NOT DO THIS): ``` streamlit # For web interface **Core dependencies:** - pandas ```
**Single vs Multi-File Decision:**- Use single file for simple applications (< 100 lines) - but still generate requirements.txt if dependencies exist- Use multi-file structure for complex applications with:291 unmodified lines- The system will automatically extract imports from app.py and generate requirements.txt- This prevents unnecessary changes to dependencies
**IF User Specifically Asks to Modify requirements.txt:**- Output ONLY plain text package names, one per line- Do NOT use markdown formatting (no ```, no bold, no headings, no lists with * or -)- Do NOT add explanatory text or descriptions- Do NOT wrap in code blocks- Just raw package names as they would appear in a real requirements.txt file- Example of CORRECT format: gradio torch transformers- Example of INCORRECT format (DO NOT DO THIS): ``` gradio # For web interface **Core dependencies:** - torch ```
**File Modification Guidelines:**- Only output files that actually need changes- If a file doesn't need modification, don't include it in the output3781 unmodified lines lowered = code.lower() return ("import streamlit" in lowered) or ("from streamlit" in lowered) or ("st." in code and "streamlit" in lowered)
def clean_requirements_txt_content(content: str) -> str: """ Clean up requirements.txt content to remove markdown formatting. This function removes code blocks, markdown lists, headers, and other formatting that might be mistakenly included by LLMs. """ if not content: return content # First, remove code blocks if present if '```' in content: content = remove_code_block(content) # Process line by line to remove markdown formatting lines = content.split('\n') clean_lines = [] for line in lines: stripped_line = line.strip() # Skip empty lines if not stripped_line: continue # Skip lines that are markdown formatting if (stripped_line == '```' or stripped_line.startswith('```') or # Skip markdown headers (## Header) but keep comments (# comment) (stripped_line.startswith('#') and len(stripped_line) > 1 and stripped_line[1] != ' ') or stripped_line.startswith('**') or # Skip bold text stripped_line.startswith('===') or # Skip section dividers stripped_line.startswith('---') or # Skip horizontal rules # Skip common explanatory text patterns stripped_line.lower().startswith('here') or stripped_line.lower().startswith('this') or stripped_line.lower().startswith('the ') or stripped_line.lower().startswith('based on') or stripped_line.lower().startswith('dependencies') or stripped_line.lower().startswith('requirements')): continue # Handle markdown list items (- item or * item) if (stripped_line.startswith('- ') or stripped_line.startswith('* ')): # Extract the package name after the list marker stripped_line = stripped_line[2:].strip() if not stripped_line: continue # Keep lines that look like valid package specifications # Valid lines: package names, git+https://, comments starting with "# " if (stripped_line.startswith('# ') or # Valid comments stripped_line.startswith('git+') or # Git dependencies stripped_line[0].isalnum() or # Package names start with alphanumeric '==' in stripped_line or # Version specifications '>=' in stripped_line or # Version specifications '<=' in stripped_line or # Version specifications '~=' in stripped_line): # Version specifications clean_lines.append(stripped_line) result = '\n'.join(clean_lines) # Ensure it ends with a newline if result and not result.endswith('\n'): result += '\n' return result if result else "# No additional dependencies required\n"
def parse_multi_file_python_output(code: str) -> dict: """Parse multi-file Python output (Gradio/Streamlit) into separate files""" files = {}11 unmodified lines if i + 1 < len(parts): filename = parts[i].strip() content = parts[i + 1].strip() # Clean up requirements.txt to remove markdown formatting if filename == 'requirements.txt': content = clean_requirements_txt_content(content) files[filename] = content else: # Single file - check if it's a space import or regular code7 unmodified lines if line.startswith('=== ') and line.endswith(' ==='): # Save previous file if current_file and current_content: files[current_file] = '\n'.join(current_content) content = '\n'.join(current_content) # Clean up requirements.txt to remove markdown formatting if current_file == 'requirements.txt': content = clean_requirements_txt_content(content) files[current_file] = content # Start new file current_file = line[4:-4].strip() current_content = []2 unmodified lines # Save last file if current_file and current_content: files[current_file] = '\n'.join(current_content) content = '\n'.join(current_content) # Clean up requirements.txt to remove markdown formatting if current_file == 'requirements.txt': content = clean_requirements_txt_content(content) files[current_file] = content else: # Single file code - determine appropriate filename if is_streamlit_code(code):34 unmodified lines # Format output for filename in ordered_files: output.append(f"=== {filename} ===") output.append(files[filename]) # Clean up requirements.txt content if it's being formatted content = files[filename] if filename == 'requirements.txt': content = clean_requirements_txt_content(content) output.append(content) output.append("") # Empty line between files return '\n'.join(output)1167 unmodified lines- One package per line- If no external packages are needed, return "# No additional dependencies required"
🚨 CRITICAL OUTPUT FORMAT:- Output ONLY the package names, one per line (plain text format)- Do NOT use markdown formatting (no ```, no bold, no headings, no lists)- Do NOT add any explanatory text before or after the package list- Do NOT wrap the output in code blocks- Just output raw package names as they would appear in requirements.txt
Generate a comprehensive requirements.txt that ensures the application will work smoothly:"""
messages = [ {"role": "system", "content": "You are a Python packaging expert specializing in creating comprehensive, production-ready requirements.txt files. Your goal is to ensure applications work smoothly by including not just direct dependencies but also commonly needed companion packages, popular extensions, and supporting libraries that developers typically need together."}, {"role": "system", "content": "You are a Python packaging expert specializing in creating comprehensive, production-ready requirements.txt files. Output ONLY plain text package names without any markdown formatting, code blocks, or explanatory text. Your goal is to ensure applications work smoothly by including not just direct dependencies but also commonly needed companion packages, popular extensions, and supporting libraries that developers typically need together."}, {"role": "user", "content": prompt} ] 10 unmodified lines if '```' in requirements_content: # Use the existing remove_code_block function for consistent cleaning requirements_content = remove_code_block(requirements_content) # Enhanced cleanup for markdown and formatting lines = requirements_content.split('\n') clean_lines = [] for line in lines: stripped_line = line.strip() # Additional cleanup for any remaining backticks # Remove any remaining standalone backticks at start/end of lines lines = requirements_content.split('\n') clean_lines = [] for line in lines: stripped_line = line.strip() # Skip lines that are just backticks or backticks with language markers if stripped_line == '```' or stripped_line.startswith('```'): continue # Skip lines that are markdown formatting if (stripped_line == '```' or stripped_line.startswith('```') or stripped_line.startswith('#') and not stripped_line.startswith('# ') or # Skip markdown headers but keep comments stripped_line.startswith('**') or # Skip bold text stripped_line.startswith('*') and not stripped_line[1:2].isalnum() or # Skip markdown lists but keep package names starting with * stripped_line.startswith('-') and not stripped_line[1:2].isalnum() or # Skip markdown lists but keep package names starting with - stripped_line.startswith('===') or # Skip section dividers stripped_line.startswith('---') or # Skip horizontal rules stripped_line.lower().startswith('here') or # Skip explanatory text stripped_line.lower().startswith('this') or # Skip explanatory text stripped_line.lower().startswith('the') or # Skip explanatory text stripped_line.lower().startswith('based on') or # Skip explanatory text stripped_line == ''): # Skip empty lines unless they're at natural boundaries continue # Keep lines that look like valid package specifications # Valid lines: package names, git+https://, comments starting with "# " if (stripped_line.startswith('# ') or # Valid comments stripped_line.startswith('git+') or # Git dependencies stripped_line[0].isalnum() or # Package names start with alphanumeric '==' in stripped_line or # Version specifications '>=' in stripped_line or # Version specifications '<=' in stripped_line): # Version specifications clean_lines.append(line) requirements_content = '\n'.join(clean_lines).strip() requirements_content = '\n'.join(clean_lines).strip() # Ensure it ends with a newline if requirements_content and not requirements_content.endswith('\n'):app.py+197-14