slimshadow commited on
Commit
11d5c32
·
verified ·
1 Parent(s): f8f3cab

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -0
  2. app/main.py +30 -0
  3. app/requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, WebSocket
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+
4
+ app = FastAPI()
5
+
6
+ # Allow CORS for local development
7
+ app.add_middleware(
8
+ CORSMiddleware,
9
+ allow_origins=["*"],
10
+ allow_credentials=True,
11
+ allow_methods=["*"],
12
+ allow_headers=["*"],
13
+ )
14
+
15
+ connected_clients = []
16
+
17
+ @app.websocket("/ws")
18
+ async def websocket_endpoint(websocket: WebSocket):
19
+ await websocket.accept()
20
+ connected_clients.append(websocket)
21
+ try:
22
+ while True:
23
+ data = await websocket.receive_text()
24
+ for client in connected_clients:
25
+ if client != websocket:
26
+ await client.send_text(data)
27
+ except Exception as e:
28
+ print(f"Client disconnected: {e}")
29
+ finally:
30
+ connected_clients.remove(websocket)
app/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn