update for react
Browse files1892 unmodified lines18931894189518961897189818995 unmodified lines19051906190719081909191019111912191319141915191619175086 unmodified lines7004700570067007700870097010701126 unmodified lines7038703970407041704270431 unmodified line70457046704770487049705070512484 unmodified lines953695379538953995409541954295431892 unmodified lines- Do NOT wrap files in Markdown code fences or use === markers inside file contentCRITICAL Requirements:1. Always include a Dockerfile configured for Node.js deployment2. Use Next.js with TypeScript/JSX (.jsx files for components)3. Include Tailwind CSS for styling (in postcss.config.js and tailwind.config.js)4. Create necessary components in the components/ directory5 unmodified lines10. Make the application fully responsive11. Include proper error handling and loading states12. Follow accessibility best practicesDockerfile Requirements:- Use Node.js 18+ base image- Install dependencies with npm install- Run "npm run build" to build Next.js app- Expose port 3000- Start with "npm start"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"""5086 unmodified lines# Deploy to Spaces logicdef add_anycoder_tag_to_readme(api, repo_id):"""Download existing README, add anycoder tag, and upload back."""try:import tempfileimport re26 unmodified lines# Add tags section with anycoderfrontmatter += '\ntags:\n- anycoder'# Reconstruct the READMEnew_content = f"---\n{frontmatter}\n---{body}"else:1 unmodified linenew_content = content.replace('---', '---\ntags:\n- anycoder\n---', 1)else:# No frontmatter, add it at the beginningnew_content = f"---\ntags:\n- anycoder\n---\n\n{content}"# Upload the modified READMEwith tempfile.NamedTemporaryFile("w", suffix=".md", delete=False, encoding='utf-8') as f:2484 unmodified linesif not success:return gr.update(value=f"Error uploading {file_name}: {last_error}", visible=True)# Add anycoder tag to existing READMEadd_anycoder_tag_to_readme(api, repo_id)space_url = f"https://huggingface.co/spaces/{repo_id}"action_text = "Updated" if is_update else "Deployed"1892 unmodified lines18931894189518961897189818995 unmodified lines1905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819795086 unmodified lines7066706770687069707070717072707370747075707670777078707926 unmodified lines71067107710871097110711171127113711471151 unmodified line711771187119712071217122712371242484 unmodified lines960996109611961296139614961596161892 unmodified lines- Do NOT wrap files in Markdown code fences or use === markers inside file contentCRITICAL Requirements:1. Always include a Dockerfile configured for Node.js deployment (see Dockerfile Requirements below)2. Use Next.js with TypeScript/JSX (.jsx files for components)3. Include Tailwind CSS for styling (in postcss.config.js and tailwind.config.js)4. Create necessary components in the components/ directory5 unmodified lines10. Make the application fully responsive11. Include proper error handling and loading states12. Follow accessibility best practices13. Configure next.config.js properly for HuggingFace Spaces deploymentnext.config.js Requirements:- Must be configured to work on any host (0.0.0.0)- Should not have hardcoded localhost references- Example minimal configuration:```javascript/** @type {import('next').NextConfig} */const nextConfig = {reactStrictMode: true,// Allow the app to work on HuggingFace Spacesoutput: 'standalone',}module.exports = nextConfig```Dockerfile Requirements (CRITICAL for HuggingFace Spaces):- Use Node.js 18+ base image (e.g., FROM node:18-slim)- Set up a user with ID 1000 for proper permissions:```RUN useradd -m -u 1000 userUSER userENV HOME=/home/user \\PATH=/home/user/.local/bin:$PATHWORKDIR $HOME/app```- ALWAYS use --chown=user with COPY and ADD commands:```COPY --chown=user package*.json ./COPY --chown=user . .```- Install dependencies: RUN npm install- Build the app: RUN npm run build- Expose port 7860 (HuggingFace Spaces default): EXPOSE 7860- Start with: CMD ["npm", "start", "--", "-p", "7860"]- If using a different port, make sure to set app_port in the README.md YAML frontmatterExample Dockerfile structure:```dockerfileFROM node:18-slim# Set up user with ID 1000RUN useradd -m -u 1000 userUSER userENV HOME=/home/user \\PATH=/home/user/.local/bin:$PATH# Set working directoryWORKDIR $HOME/app# Copy package files with proper ownershipCOPY --chown=user package*.json ./# Install dependenciesRUN npm install# Copy rest of the application with proper ownershipCOPY --chown=user . .# Build the Next.js appRUN npm run build# Expose port 7860EXPOSE 7860# Start the application on port 7860CMD ["npm", "start", "--", "-p", "7860"]```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"""5086 unmodified lines# Deploy to Spaces logicdef add_anycoder_tag_to_readme(api, repo_id, app_port=None):"""Download existing README, add anycoder tag and app_port if needed, and upload back.Args:api: HuggingFace API clientrepo_id: Repository IDapp_port: Optional port number to set for Docker spaces (e.g., 7860 for React apps)"""try:import tempfileimport re26 unmodified lines# Add tags section with anycoderfrontmatter += '\ntags:\n- anycoder'# Add app_port if specified and not already presentif app_port is not None and 'app_port:' not in frontmatter:frontmatter += f'\napp_port: {app_port}'# Reconstruct the READMEnew_content = f"---\n{frontmatter}\n---{body}"else:1 unmodified linenew_content = content.replace('---', '---\ntags:\n- anycoder\n---', 1)else:# No frontmatter, add it at the beginningapp_port_line = f'\napp_port: {app_port}' if app_port else ''new_content = f"---\ntags:\n- anycoder{app_port_line}\n---\n\n{content}"# Upload the modified READMEwith tempfile.NamedTemporaryFile("w", suffix=".md", delete=False, encoding='utf-8') as f:2484 unmodified linesif not success:return gr.update(value=f"Error uploading {file_name}: {last_error}", visible=True)# Add anycoder tag and app_port to existing READMEadd_anycoder_tag_to_readme(api, repo_id, app_port=7860)space_url = f"https://huggingface.co/spaces/{repo_id}"action_text = "Updated" if is_update else "Deployed"
app.py+85-12