akhaliq HF Staff commited on
Commit
a6cd23f
·
1 Parent(s): cb0c0c1
Files changed (1) hide show
  1. anycoder_app/ui.py +39 -1
anycoder_app/ui.py CHANGED
@@ -1111,6 +1111,38 @@ with gr.Blocks(
1111
  if not files:
1112
  return gr.update(value="Error: Could not parse React output. Please regenerate the code.", visible=True)
1113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1114
  # Upload React files
1115
  import tempfile
1116
  import time
@@ -1125,7 +1157,13 @@ with gr.Blocks(
1125
 
1126
  for attempt in range(max_attempts):
1127
  try:
1128
- with tempfile.NamedTemporaryFile("w", suffix=f".{file_name.split('.')[-1]}", delete=False) as f:
 
 
 
 
 
 
1129
  f.write(file_content)
1130
  temp_path = f.name
1131
 
 
1111
  if not files:
1112
  return gr.update(value="Error: Could not parse React output. Please regenerate the code.", visible=True)
1113
 
1114
+ # If Dockerfile is missing, use template
1115
+ if 'Dockerfile' not in files:
1116
+ files['Dockerfile'] = """FROM node:18-slim
1117
+
1118
+ # Set up user with ID 1000
1119
+ RUN useradd -m -u 1000 user
1120
+ USER user
1121
+ ENV HOME=/home/user \\
1122
+ PATH=/home/user/.local/bin:$PATH
1123
+
1124
+ # Set working directory
1125
+ WORKDIR $HOME/app
1126
+
1127
+ # Copy package files with proper ownership
1128
+ COPY --chown=user package*.json ./
1129
+
1130
+ # Install dependencies
1131
+ RUN npm install
1132
+
1133
+ # Copy rest of the application with proper ownership
1134
+ COPY --chown=user . .
1135
+
1136
+ # Build the Next.js app
1137
+ RUN npm run build
1138
+
1139
+ # Expose port 7860
1140
+ EXPOSE 7860
1141
+
1142
+ # Start the application on port 7860
1143
+ CMD ["npm", "start", "--", "-p", "7860"]
1144
+ """
1145
+
1146
  # Upload React files
1147
  import tempfile
1148
  import time
 
1157
 
1158
  for attempt in range(max_attempts):
1159
  try:
1160
+ # Determine file extension
1161
+ if file_name == 'Dockerfile':
1162
+ suffix = ''
1163
+ else:
1164
+ suffix = f".{file_name.split('.')[-1]}"
1165
+
1166
+ with tempfile.NamedTemporaryFile("w", suffix=suffix, delete=False) as f:
1167
  f.write(file_content)
1168
  temp_path = f.name
1169