fix requirements.txt issue
Browse files482 unmodified lines483484485486487488298 unmodified lines787788789790791792672 unmodified lines146514661467146814691470291 unmodified lines1762176317641765176617673781 unmodified lines55495550555155525553555411 unmodified lines5566556755685569557055717 unmodified lines55795580558155825583558455852 unmodified lines558855895590559155925593559434 unmodified lines56295630563156325633563456351167 unmodified lines680368046805680668076808680968106811681210 unmodified lines682368246825682668276828682968306831683268336834683568366837683868396840482 unmodified lines- Include supporting packages (accelerate, torch, tokenizers, etc.) when using ML libraries- Your requirements.txt should ensure the application works smoothly in production**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]```**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]```**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**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 lineslowered = code.lower()return ("import streamlit" in lowered) or ("from streamlit" in lowered) or ("st." in code and "streamlit" in lowered)def parse_multi_file_python_output(code: str) -> dict:"""Parse multi-file Python output (Gradio/Streamlit) into separate files"""files = {}11 unmodified linesif i + 1 < len(parts):filename = parts[i].strip()content = parts[i + 1].strip()files[filename] = contentelse:# Single file - check if it's a space import or regular code7 unmodified linesif line.startswith('=== ') and line.endswith(' ==='):# Save previous fileif current_file and current_content:files[current_file] = '\n'.join(current_content)# Start new filecurrent_file = line[4:-4].strip()current_content = []2 unmodified lines# Save last fileif current_file and current_content:files[current_file] = '\n'.join(current_content)else:# Single file code - determine appropriate filenameif is_streamlit_code(code):34 unmodified lines# Format outputfor filename in ordered_files:output.append(f"=== {filename} ===")output.append(files[filename])output.append("") # Empty line between filesreturn '\n'.join(output)1167 unmodified lines- One package per line- If no external packages are needed, return "# No additional dependencies required"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": "user", "content": prompt}]10 unmodified linesif '```' in requirements_content:# Use the existing remove_code_block function for consistent cleaningrequirements_content = remove_code_block(requirements_content)# Additional cleanup for any remaining backticks# Remove any remaining standalone backticks at start/end of lineslines = requirements_content.split('\n')clean_lines = []for line in lines:stripped_line = line.strip()# Skip lines that are just backticks or backticks with language markersif stripped_line == '```' or stripped_line.startswith('```'):continueclean_lines.append(line)requirements_content = '\n'.join(clean_lines).strip()# Ensure it ends with a newlineif requirements_content and not requirements_content.endswith('\n'):482 unmodified lines483484485486487488489490491492493494495496497498499500501502503504505298 unmodified lines804805806807808809810811812813814815816817818819820821822823824825826672 unmodified lines14991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521291 unmodified lines181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418353781 unmodified lines561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568911 unmodified lines570157025703570457055706570757085709571057117 unmodified lines571957205721572257235724572557265727572857292 unmodified lines5732573357345735573657375738573957405741574234 unmodified lines57775778577957805781578257835784578557865787578857891167 unmodified lines6957695869596960696169626963696469656966696769686969697069716972697310 unmodified lines6984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023482 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:gradiotorchtransformers- 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:gradiotorchtransformers- 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:streamlitpandasnumpy- 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:gradiotorchtransformers- 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 lineslowered = 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 formattingthat might be mistakenly included by LLMs."""if not content:return content# First, remove code blocks if presentif '```' in content:content = remove_code_block(content)# Process line by line to remove markdown formattinglines = content.split('\n')clean_lines = []for line in lines:stripped_line = line.strip()# Skip empty linesif not stripped_line:continue# Skip lines that are markdown formattingif (stripped_line == '```' orstripped_line.startswith('```') or# Skip markdown headers (## Header) but keep comments (# comment)(stripped_line.startswith('#') and len(stripped_line) > 1 and stripped_line[1] != ' ') orstripped_line.startswith('**') or # Skip bold textstripped_line.startswith('===') or # Skip section dividersstripped_line.startswith('---') or # Skip horizontal rules# Skip common explanatory text patternsstripped_line.lower().startswith('here') orstripped_line.lower().startswith('this') orstripped_line.lower().startswith('the ') orstripped_line.lower().startswith('based on') orstripped_line.lower().startswith('dependencies') orstripped_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 markerstripped_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 commentsstripped_line.startswith('git+') or # Git dependenciesstripped_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 specificationsclean_lines.append(stripped_line)result = '\n'.join(clean_lines)# Ensure it ends with a newlineif 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 linesif i + 1 < len(parts):filename = parts[i].strip()content = parts[i + 1].strip()# Clean up requirements.txt to remove markdown formattingif filename == 'requirements.txt':content = clean_requirements_txt_content(content)files[filename] = contentelse:# Single file - check if it's a space import or regular code7 unmodified linesif line.startswith('=== ') and line.endswith(' ==='):# Save previous fileif current_file and current_content:content = '\n'.join(current_content)# Clean up requirements.txt to remove markdown formattingif current_file == 'requirements.txt':content = clean_requirements_txt_content(content)files[current_file] = content# Start new filecurrent_file = line[4:-4].strip()current_content = []2 unmodified lines# Save last fileif current_file and current_content:content = '\n'.join(current_content)# Clean up requirements.txt to remove markdown formattingif current_file == 'requirements.txt':content = clean_requirements_txt_content(content)files[current_file] = contentelse:# Single file code - determine appropriate filenameif is_streamlit_code(code):34 unmodified lines# Format outputfor filename in ordered_files:output.append(f"=== {filename} ===")# Clean up requirements.txt content if it's being formattedcontent = files[filename]if filename == 'requirements.txt':content = clean_requirements_txt_content(content)output.append(content)output.append("") # Empty line between filesreturn '\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.txtGenerate 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. 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 linesif '```' in requirements_content:# Use the existing remove_code_block function for consistent cleaningrequirements_content = remove_code_block(requirements_content)# Enhanced cleanup for markdown and formattinglines = requirements_content.split('\n')clean_lines = []for line in lines:stripped_line = line.strip()# Skip lines that are markdown formattingif (stripped_line == '```' orstripped_line.startswith('```') orstripped_line.startswith('#') and not stripped_line.startswith('# ') or # Skip markdown headers but keep commentsstripped_line.startswith('**') or # Skip bold textstripped_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 dividersstripped_line.startswith('---') or # Skip horizontal rulesstripped_line.lower().startswith('here') or # Skip explanatory textstripped_line.lower().startswith('this') or # Skip explanatory textstripped_line.lower().startswith('the') or # Skip explanatory textstripped_line.lower().startswith('based on') or # Skip explanatory textstripped_line == ''): # Skip empty lines unless they're at natural boundariescontinue# Keep lines that look like valid package specifications# Valid lines: package names, git+https://, comments starting with "# "if (stripped_line.startswith('# ') or # Valid commentsstripped_line.startswith('git+') or # Git dependenciesstripped_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 specificationsclean_lines.append(line)requirements_content = '\n'.join(clean_lines).strip()# Ensure it ends with a newlineif requirements_content and not requirements_content.endswith('\n'):
app.py+197-14