update for react
Browse files1892 unmodified lines189318941895189618961897189818995 unmodified lines1905190619071908190919091910191119121913191419101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819795086 unmodified lines706670677068700770087069707070717072707370747075707670777078707926 unmodified lines71067107710871097110711171127113711471151 unmodified line7117711871197120704871217122712371242484 unmodified lines96099610961195399540961296139614961596161892 unmodified lines- Do NOT wrap files in Markdown code fences or use === markers inside file content
CRITICAL Requirements:1. Always include a Dockerfile configured for Node.js deployment1. 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 deployment
Dockerfile 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"next.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 Spaces output: '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 user USER user ENV HOME=/home/user \\ PATH=/home/user/.local/bin:$PATH WORKDIR $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 frontmatter
Example 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 logic
def add_anycoder_tag_to_readme(api, repo_id): """Download existing README, add anycoder tag, and upload back."""def 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 client repo_id: Repository ID app_port: Optional port number to set for Docker spaces (e.g., 7860 for React apps) """ try: import tempfile import re26 unmodified lines # Add tags section with anycoder frontmatter += '\ntags:\n- anycoder' # Add app_port if specified and not already present if app_port is not None and 'app_port:' not in frontmatter: frontmatter += f'\napp_port: {app_port}' # Reconstruct the README new_content = f"---\n{frontmatter}\n---{body}" else:1 unmodified line new_content = content.replace('---', '---\ntags:\n- anycoder\n---', 1) else: # No frontmatter, add it at the beginning app_port_line = f'\napp_port: {app_port}' if app_port else '' new_content = f"---\ntags:\n- anycoder\n---\n\n{content}" new_content = f"---\ntags:\n- anycoder{app_port_line}\n---\n\n{content}" # Upload the modified README with tempfile.NamedTemporaryFile("w", suffix=".md", delete=False, encoding='utf-8') as f:2484 unmodified lines if not success: return gr.update(value=f"Error uploading {file_name}: {last_error}", visible=True) # Add anycoder tag to existing README add_anycoder_tag_to_readme(api, repo_id) # Add anycoder tag and app_port to existing README add_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