Carley1234 commited on
Commit
8ec65c0
·
verified ·
1 Parent(s): d205ae5

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +15 -0
  2. README.md +17 -5
  3. app.py +69 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ # Create data directory with permissions
11
+ RUN mkdir -p /app/data && chmod 777 /app/data
12
+
13
+ EXPOSE 7860
14
+
15
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,5 +1,17 @@
1
- ---
2
- license: other
3
- license_name: cn
4
- license_link: LICENSE
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: CE Data Collector
3
+ emoji: 📊
4
+ colorFrom: green
5
+ colorTo: lime
6
+ sdk: docker
7
+ pinned: false
8
+ app_port: 7860
9
+ ---
10
+
11
+ # Creative Engine Data Collector
12
+
13
+ This API receives anonymous CES code snippets and metadata from the Creative Engine editor for training purposes.
14
+
15
+ ## API Endpoint
16
+
17
+ - `POST /collect`: Accepts a JSON object with `scripts` and `metadata`.
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ import json
4
+ import os
5
+ import time
6
+ from datetime import datetime
7
+
8
+ app = FastAPI()
9
+
10
+ # Enable CORS for the editor
11
+ app.add_middleware(
12
+ CORSMiddleware,
13
+ allow_origins=["*"],
14
+ allow_credentials=True,
15
+ allow_methods=["*"],
16
+ allow_headers=["*"],
17
+ )
18
+
19
+ # Directory to store collected datasets (simulating HF Dataset storage)
20
+ DATA_DIR = "/app/data"
21
+ os.makedirs(DATA_DIR, exist_ok=True)
22
+
23
+ @app.get("/")
24
+ async def root():
25
+ return {"message": "Creative Engine Data Collector is running"}
26
+
27
+ @app.post("/collect")
28
+ async def collect_data(request: Request):
29
+ try:
30
+ data = await request.json()
31
+
32
+ # We expect: { "scripts": [...], "metadata": { "engineVersion": "0.1.2", ... } }
33
+ timestamp = int(time.time())
34
+ filename = f"ces_collection_{timestamp}.json"
35
+ filepath = os.path.join(DATA_DIR, filename)
36
+
37
+ # Save to local disk
38
+ with open(filepath, "w", encoding="utf-8") as f:
39
+ json.dump(data, f, ensure_ascii=False, indent=2)
40
+
41
+ # Optional: Push to Hugging Face Hub if token is present
42
+ hf_token = os.environ.get("HF_TOKEN")
43
+ dataset_repo = "Carley1234/DatosdeentrenamientodeCreativeCode"
44
+
45
+ if hf_token:
46
+ try:
47
+ from huggingface_hub import HfApi
48
+ api = HfApi()
49
+ api.upload_file(
50
+ path_or_fileobj=filepath,
51
+ path_in_repo=f"data/{filename}",
52
+ repo_id=dataset_repo,
53
+ repo_type="dataset",
54
+ token=hf_token
55
+ )
56
+ print(f"Successfully pushed {filename} to {dataset_repo}")
57
+ except Exception as hf_err:
58
+ print(f"Failed to push to HF Hub: {hf_err}")
59
+
60
+ print(f"Collected data from engine version {data.get('metadata', {}).get('engineVersion')}")
61
+
62
+ return {"status": "success", "file": filename}
63
+ except Exception as e:
64
+ print(f"Error collecting data: {e}")
65
+ return {"status": "error", "message": str(e)}
66
+
67
+ if __name__ == "__main__":
68
+ import uvicorn
69
+ uvicorn.run(app, host="0.0.0.0", port=7860)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ python-multipart
4
+ huggingface_hub