josephrw commited on
Commit
9887034
·
verified ·
1 Parent(s): 6366a5e

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -0
  2. README.md +8 -9
  3. app.py +42 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+ WORKDIR /app
3
+ COPY app.py /app/app.py
4
+ RUN pip install --no-cache-dir fastapi==0.115.6 uvicorn[standard]==0.34.0 httpx==0.28.1
5
+ ENV PORT=7860
6
+ EXPOSE 7860
7
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: Engine Relay
3
- emoji: 💻
4
- colorFrom: yellow
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 6.19.0
8
- python_version: '3.13'
9
- app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: Continuity Code Camera Relay
3
+ emoji: 🎥
4
+ colorFrom: indigo
5
+ colorTo: green
6
+ sdk: docker
 
 
 
7
  pinned: false
8
  ---
9
 
10
+ # Continuity Code Camera Relay
11
+
12
+ Public Hugging Face relay/card for a local Ollama-backed Code Camera Engine.
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import httpx
4
+ from fastapi import FastAPI, Request
5
+ from fastapi.responses import HTMLResponse, JSONResponse
6
+
7
+ app = FastAPI(title="Continuity Code Camera Relay")
8
+ LOCAL_ENGINE_URL = os.getenv("LOCAL_ENGINE_URL", "").rstrip("/")
9
+
10
+ @app.get("/", response_class=HTMLResponse)
11
+ def index():
12
+ target = LOCAL_ENGINE_URL or "SET_LOCAL_ENGINE_URL_SECRET"
13
+ return f"""<!doctype html>
14
+ <html><head><meta name="viewport" content="width=device-width,initial-scale=1"><title>Continuity Code Camera Relay</title></head>
15
+ <body style="font-family:system-ui;background:#070910;color:#fff;padding:20px">
16
+ <h1>Continuity Code Camera Relay</h1>
17
+ <p>This Space relays to your local Ollama-backed live engine.</p>
18
+ <p><b>Target:</b> {target}</p>
19
+ <p>Open the local/tunnel target directly for camera permissions and lowest latency:</p>
20
+ <p><a style="color:#82aaff" href="{target}">{target}</a></p>
21
+ </body></html>"""
22
+
23
+ @app.get("/health")
24
+ async def health():
25
+ if not LOCAL_ENGINE_URL:
26
+ return {"ok": False, "reason": "LOCAL_ENGINE_URL not set"}
27
+ async with httpx.AsyncClient(timeout=10) as client:
28
+ r = await client.get(f"{LOCAL_ENGINE_URL}/health")
29
+ return {"ok": True, "relay_target": LOCAL_ENGINE_URL, "engine": r.json()}
30
+
31
+ @app.api_route("/proxy/{path:path}", methods=["GET","POST","PUT","DELETE","PATCH"])
32
+ async def proxy(path: str, request: Request):
33
+ if not LOCAL_ENGINE_URL:
34
+ return JSONResponse({"ok": False, "reason": "LOCAL_ENGINE_URL not set"}, status_code=500)
35
+ body = await request.body()
36
+ headers = {k:v for k,v in request.headers.items() if k.lower() not in {"host","content-length"}}
37
+ async with httpx.AsyncClient(timeout=60) as client:
38
+ r = await client.request(request.method, f"{LOCAL_ENGINE_URL}/{path}", content=body, headers=headers, params=request.query_params)
39
+ ct = r.headers.get("content-type","")
40
+ if "application/json" in ct:
41
+ return JSONResponse(r.json(), status_code=r.status_code)
42
+ return JSONResponse({"text": r.text}, status_code=r.status_code)