Spaces:
Sleeping
Sleeping
Commit ·
8c04068
1
Parent(s): 5290248
issue fixed 007
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import torch
|
| 4 |
-
import datetime
|
| 5 |
from flask import Flask, request, render_template, jsonify, Response
|
| 6 |
from flasgger import Swagger, swag_from
|
| 7 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
@@ -65,17 +64,6 @@ def is_incomplete(text):
|
|
| 65 |
|
| 66 |
search_tool = DuckDuckGoSearchRun()
|
| 67 |
|
| 68 |
-
def determine_folder(name):
|
| 69 |
-
ext = name.split('.')[-1].lower()
|
| 70 |
-
if ext in {"js", "jsx", "ts", "tsx", "html", "css"}:
|
| 71 |
-
return "frontend"
|
| 72 |
-
elif ext in {"py", "java", "cs", "go"}:
|
| 73 |
-
return "backend"
|
| 74 |
-
elif ext in {"sql", "prisma", "db"}:
|
| 75 |
-
return "database"
|
| 76 |
-
else:
|
| 77 |
-
return "misc"
|
| 78 |
-
|
| 79 |
# ✅ Chat Completion using Phi-4
|
| 80 |
# @GPU
|
| 81 |
# def generate_full_reply(message, history):
|
|
@@ -362,49 +350,26 @@ def chat_stream_doc():
|
|
| 362 |
return jsonify({"error": "No files found in generated output."}), 500
|
| 363 |
|
| 364 |
zip_buffer = BytesIO()
|
| 365 |
-
file_list = []
|
| 366 |
-
file_count = 0
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zipf:
|
|
|
|
| 371 |
for match in matches:
|
| 372 |
-
|
| 373 |
code = match.group(2).strip()
|
| 374 |
-
|
| 375 |
-
# full_path = f"{folder}/{raw_filename}"
|
| 376 |
-
zipf.writestr(raw_filename, code)
|
| 377 |
-
# file_list.append(full_path)
|
| 378 |
file_count += 1
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
# f"**Backend:** {backend}\n"
|
| 385 |
-
# f"**Database:** {database}\n\n"
|
| 386 |
-
# f"**Generated on:** {datetime.datetime.now().isoformat()}\n"
|
| 387 |
-
# f"**Files:** {file_count}\n\n"
|
| 388 |
-
# "This project was auto-generated using AI from a requirement document.\n"
|
| 389 |
-
# )
|
| 390 |
-
# zipf.writestr("README.md", readme)
|
| 391 |
-
# file_list.append("README.md")
|
| 392 |
-
|
| 393 |
-
if file_count == 0:
|
| 394 |
-
return jsonify({"error": "No files found in generated output."}), 500
|
| 395 |
|
| 396 |
zip_buffer.seek(0)
|
| 397 |
-
|
| 398 |
zip_buffer,
|
| 399 |
mimetype='application/zip',
|
| 400 |
headers={"Content-Disposition": "attachment; filename=generated_project.zip"}
|
| 401 |
)
|
| 402 |
|
| 403 |
-
# Optional: attach log
|
| 404 |
-
# response.headers["X-Generated-Files"] = ", ".join(file_list)
|
| 405 |
-
|
| 406 |
-
# return response
|
| 407 |
-
|
| 408 |
|
| 409 |
# ✅ Warm-up
|
| 410 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import torch
|
|
|
|
| 4 |
from flask import Flask, request, render_template, jsonify, Response
|
| 5 |
from flasgger import Swagger, swag_from
|
| 6 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
|
| 64 |
|
| 65 |
search_tool = DuckDuckGoSearchRun()
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# ✅ Chat Completion using Phi-4
|
| 68 |
# @GPU
|
| 69 |
# def generate_full_reply(message, history):
|
|
|
|
| 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 |
+
file_count = 0
|
| 355 |
for match in matches:
|
| 356 |
+
filename = match.group(1).strip().rstrip("`")
|
| 357 |
code = match.group(2).strip()
|
| 358 |
+
zipf.writestr(filename, code)
|
|
|
|
|
|
|
|
|
|
| 359 |
file_count += 1
|
| 360 |
|
| 361 |
+
if file_count == 0:
|
| 362 |
+
print("⚠️ No files written to ZIP. Check LLM output format.")
|
| 363 |
+
print("LLM Reply:\n", reply)
|
| 364 |
+
return jsonify({"error": "No files found in generated output."}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
zip_buffer.seek(0)
|
| 367 |
+
return Response(
|
| 368 |
zip_buffer,
|
| 369 |
mimetype='application/zip',
|
| 370 |
headers={"Content-Disposition": "attachment; filename=generated_project.zip"}
|
| 371 |
)
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
# ✅ Warm-up
|
| 375 |
if __name__ == "__main__":
|