Spaces:
Build error
Build error
Upload 4 files
Browse files- README.md +9 -12
- app.py +48 -0
- requirements.txt +1 -0
- space.yaml +11 -0
README.md
CHANGED
|
@@ -1,13 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
title: CodeZipper
|
| 3 |
-
emoji: 📉
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: gray
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.49.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
short_description: Bundles AI generated code into a downloadable zip file
|
| 11 |
-
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI Project Packager (Hugging Face Space)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
This Space lets you paste AI-generated multi-file project responses and automatically turns them into a downloadable `.zip` ready for local use.
|
| 4 |
+
|
| 5 |
+
## How to Use
|
| 6 |
+
1. Paste an AI-generated project (with multiple ``` code blocks) into the text box.
|
| 7 |
+
2. The Space detects filenames and code blocks.
|
| 8 |
+
3. Click “Submit” to generate and download a ready-to-run ZIP file.
|
| 9 |
+
|
| 10 |
+
Built with **Gradio**.
|
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re, os, zipfile, tempfile
|
| 3 |
+
|
| 4 |
+
def parse_ai_response(text):
|
| 5 |
+
files = []
|
| 6 |
+
pattern = r"```([a-zA-Z0-9]+)?\n([\s\S]*?)```"
|
| 7 |
+
matches = re.findall(pattern, text)
|
| 8 |
+
|
| 9 |
+
lines = text.splitlines()
|
| 10 |
+
inferred_names = []
|
| 11 |
+
for i, line in enumerate(lines):
|
| 12 |
+
if re.search(r"(`.*?`|\.js|\.html|\.css|\.py)", line):
|
| 13 |
+
m = re.search(r"([A-Za-z0-9_\-]+\.[A-Za-z0-9]+)", line)
|
| 14 |
+
if m:
|
| 15 |
+
inferred_names.append(m.group(1))
|
| 16 |
+
|
| 17 |
+
for i, (lang, code) in enumerate(matches):
|
| 18 |
+
filename = inferred_names[i] if i < len(inferred_names) else f"file_{i+1}.{lang or 'txt'}"
|
| 19 |
+
files.append((filename, code))
|
| 20 |
+
return files
|
| 21 |
+
|
| 22 |
+
def create_zip(files):
|
| 23 |
+
temp_dir = tempfile.mkdtemp()
|
| 24 |
+
zip_path = os.path.join(temp_dir, "project.zip")
|
| 25 |
+
with zipfile.ZipFile(zip_path, "w") as zipf:
|
| 26 |
+
for name, content in files:
|
| 27 |
+
file_path = os.path.join(temp_dir, name)
|
| 28 |
+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
| 29 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 30 |
+
f.write(content)
|
| 31 |
+
zipf.write(file_path, arcname=name)
|
| 32 |
+
return zip_path
|
| 33 |
+
|
| 34 |
+
def process_response(text):
|
| 35 |
+
files = parse_ai_response(text)
|
| 36 |
+
zip_path = create_zip(files)
|
| 37 |
+
return zip_path
|
| 38 |
+
|
| 39 |
+
interface = gr.Interface(
|
| 40 |
+
fn=process_response,
|
| 41 |
+
inputs=gr.Textbox(lines=30, label="Paste AI project response here"),
|
| 42 |
+
outputs=gr.File(label="Download generated ZIP"),
|
| 43 |
+
title="AI Project Packager",
|
| 44 |
+
description="Paste an AI-generated project (like a Node.js or Python app) and this tool will parse, assemble, and zip the files for you."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0
|
space.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# space.yaml
|
| 2 |
+
title: AI Project Packager
|
| 3 |
+
emoji: 📦
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
runtime: python3.10
|