Adrian Gabriel commited on
Commit
21c9528
·
1 Parent(s): 0652520

latest changs

Browse files
Files changed (3) hide show
  1. .github/workflows/sync_to_hub.yml +20 -0
  2. app.py +23 -0
  3. requirements.txt +2 -1
.github/workflows/sync_to_hub.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face Hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push https://<HF_USERNAME>:$HF_TOKEN@huggingface.co/spaces/<HF_USERNAME>/<SPACE_NAME> main
app.py CHANGED
@@ -2,6 +2,7 @@ from __future__ import annotations
2
 
3
  import ast
4
  import asyncio
 
5
  import queue
6
  import traceback
7
  from pathlib import Path
@@ -262,3 +263,25 @@ async def ws_endpoint(ws: WebSocket):
262
 
263
  except WebSocketDisconnect:
264
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import ast
4
  import asyncio
5
+ import os
6
  import queue
7
  import traceback
8
  from pathlib import Path
 
263
 
264
  except WebSocketDisconnect:
265
  return
266
+
267
+
268
+ # Entry point for running the app
269
+ if __name__ == "__main__":
270
+ import uvicorn
271
+
272
+ # Support for Hugging Face Spaces (uses port 7860) and local development
273
+ # HF Spaces sets SPACE_ID environment variable
274
+ is_hf_space = os.environ.get("SPACE_ID") is not None
275
+
276
+ # Get host and port from environment variables, with sensible defaults
277
+ host = os.environ.get("HOST", "0.0.0.0" if is_hf_space else "127.0.0.1")
278
+ port = int(os.environ.get("PORT", "7860" if is_hf_space else "8000"))
279
+
280
+ print(f"Starting TinyTorch Visualizer on http://{host}:{port}")
281
+ if is_hf_space:
282
+ print("Running in Hugging Face Spaces mode")
283
+ else:
284
+ print("Running in local development mode")
285
+ print(f"Open http://localhost:{port} in your browser")
286
+
287
+ uvicorn.run(app, host=host, port=port)
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  fastapi
2
- uvicorn
3
  numpy
 
4
  # Add any other libraries you import in your python code
 
1
  fastapi
2
+ uvicorn[standard]
3
  numpy
4
+ websockets
5
  # Add any other libraries you import in your python code