FrederickSundeep commited on
Commit
fe1db2c
·
1 Parent(s): afbc727

issue fixed 003

Browse files
Files changed (1) hide show
  1. app.py +39 -13
app.py CHANGED
@@ -302,32 +302,58 @@ def chat_stream_doc():
302
 
303
  tech_stack = f"Frontend: {frontend}\nBackend: {backend}\nDatabase: {database}"
304
  prompt = (
305
- f"You are a full-stack project generator.\n\n"
306
- f"Requirement Document:\n{content}\n\n"
307
- f"{tech_stack}\n\n"
308
- f"Generate a complete project scaffold including:\n"
309
- f"- Backend (API routes, models, server config)\n"
310
- f"- Frontend (UI components, service calls)\n"
311
- f"- Database schema\n"
312
- f"Reply with full code organized as multiple files with filenames."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  )
314
 
315
  # ✅ Generate response from Phi-4
316
  reply = generate_full_reply(prompt, [])
317
 
318
  # ✅ Extract filenames and code from reply
319
- file_pattern = r"### File: (.+?)\n```(.*?)```"
320
  matches = re.finditer(file_pattern, reply, re.DOTALL)
321
 
322
  if not matches:
 
 
323
  return jsonify({"error": "No files found in generated output."}), 500
324
 
325
  zip_buffer = BytesIO()
326
  with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zipf:
327
- for match in matches:
328
- name = match.group(1).strip()
329
- code = match.group(2).strip()
330
- zipf.writestr(name, code)
331
 
332
  zip_buffer.seek(0)
333
  return Response(
 
302
 
303
  tech_stack = f"Frontend: {frontend}\nBackend: {backend}\nDatabase: {database}"
304
  prompt = (
305
+ "You are a full-stack project code generator.\n\n"
306
+ "Below is a requirement document followed by technology preferences. Based on this, generate the full project scaffold.\n\n"
307
+ "Requirement Document:\n"
308
+ f"{content}\n\n"
309
+ f"Technology Stack:\nFrontend: {frontend}\nBackend: {backend}\nDatabase: {database}\n\n"
310
+ "Your task:\n"
311
+ "- Analyze the requirement and tech stack.\n"
312
+ "- Generate backend code: models, routes, and config.\n"
313
+ "- Generate frontend code: components, services.\n"
314
+ "- Define the database schema.\n\n"
315
+ "✅ Format the output as multiple files in this exact structure:\n\n"
316
+ "### File: <filename>\n"
317
+ "```<language>\n"
318
+ "<code content>\n"
319
+ "```\n\n"
320
+ "For example:\n\n"
321
+ "### File: app.py\n"
322
+ "```python\n"
323
+ "from flask import Flask\n"
324
+ "app = Flask(__name__)\n"
325
+ "@app.route('/')\n"
326
+ "def home():\n"
327
+ " return 'Hello, world!'\n"
328
+ "```\n\n"
329
+ "### File: frontend/App.js\n"
330
+ "```javascript\n"
331
+ "import React from 'react';\n"
332
+ "function App() {\n"
333
+ " return <h1>Hello from React</h1>;\n"
334
+ "}\n"
335
+ "export default App;\n"
336
+ "```\n\n"
337
+ "Now generate the complete project below 👇"
338
  )
339
 
340
  # ✅ Generate response from Phi-4
341
  reply = generate_full_reply(prompt, [])
342
 
343
  # ✅ Extract filenames and code from reply
344
+ file_pattern = r"### File:\s*(.+?)\n```(?:\w+)?\n(.*?)```"
345
  matches = re.finditer(file_pattern, reply, re.DOTALL)
346
 
347
  if not matches:
348
+ print("⚠️ No file matches found in reply.")
349
+ print("Raw reply:\n", reply)
350
  return jsonify({"error": "No files found in generated output."}), 500
351
 
352
  zip_buffer = BytesIO()
353
  with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zipf:
354
+ for filename, code in matches:
355
+ print(f"✅ Writing file: {filename}")
356
+ zipf.writestr(filename.strip(), code.strip())
 
357
 
358
  zip_buffer.seek(0)
359
  return Response(