crosse712 commited on
Commit
08511e7
ยท
1 Parent(s): 6bfe886

Add Hugging Face Spaces deployment configuration for frontend+backend

Browse files
Files changed (3) hide show
  1. Dockerfile.hf +88 -0
  2. README_HF_SPACE.md +56 -0
  3. frontend/src/App.jsx +1 -1
Dockerfile.hf ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Spaces Dockerfile - Frontend + Backend
2
+ FROM node:18-slim as frontend-builder
3
+
4
+ WORKDIR /app/frontend
5
+ COPY frontend/package*.json ./
6
+ RUN npm ci
7
+ COPY frontend/ ./
8
+ RUN npm run build
9
+
10
+ # Python backend stage
11
+ FROM python:3.9-slim
12
+
13
+ WORKDIR /app
14
+
15
+ # Install system dependencies
16
+ RUN apt-get update && apt-get install -y \
17
+ nginx \
18
+ supervisor \
19
+ libgomp1 \
20
+ libglib2.0-0 \
21
+ libsm6 \
22
+ libxext6 \
23
+ libxrender1 \
24
+ curl \
25
+ && rm -rf /var/lib/apt/lists/*
26
+
27
+ # Install Python dependencies
28
+ COPY backend/requirements.txt ./backend/
29
+ RUN pip install --no-cache-dir -r backend/requirements.txt
30
+
31
+ # Copy backend code
32
+ COPY backend/ ./backend/
33
+
34
+ # Copy frontend build from builder stage
35
+ COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
36
+
37
+ # Configure nginx to serve frontend and proxy to backend
38
+ RUN echo 'server { \n\
39
+ listen 7860; \n\
40
+ root /usr/share/nginx/html; \n\
41
+ index index.html; \n\
42
+ \n\
43
+ location / { \n\
44
+ try_files $uri $uri/ /index.html; \n\
45
+ } \n\
46
+ \n\
47
+ location /api/ { \n\
48
+ proxy_pass http://127.0.0.1:8000/; \n\
49
+ proxy_http_version 1.1; \n\
50
+ proxy_set_header Upgrade $http_upgrade; \n\
51
+ proxy_set_header Connection "upgrade"; \n\
52
+ proxy_set_header Host $host; \n\
53
+ proxy_set_header X-Real-IP $remote_addr; \n\
54
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n\
55
+ proxy_set_header X-Forwarded-Proto $scheme; \n\
56
+ proxy_buffering off; \n\
57
+ } \n\
58
+ }' > /etc/nginx/sites-available/default
59
+
60
+ # Create supervisor config
61
+ RUN echo '[supervisord] \n\
62
+ nodaemon=true \n\
63
+ \n\
64
+ [program:nginx] \n\
65
+ command=nginx -g "daemon off;" \n\
66
+ autostart=true \n\
67
+ autorestart=true \n\
68
+ stderr_logfile=/var/log/nginx.err.log \n\
69
+ stdout_logfile=/var/log/nginx.out.log \n\
70
+ \n\
71
+ [program:backend] \n\
72
+ command=python -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 \n\
73
+ directory=/app \n\
74
+ autostart=true \n\
75
+ autorestart=true \n\
76
+ stderr_logfile=/var/log/backend.err.log \n\
77
+ stdout_logfile=/var/log/backend.out.log \n\
78
+ environment=USE_EXTREME_OPTIMIZATION="true",MAX_MEMORY_GB="3"' > /etc/supervisor/conf.d/supervisord.conf
79
+
80
+ # Expose Hugging Face Spaces default port
81
+ EXPOSE 7860
82
+
83
+ # Health check
84
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
85
+ CMD curl -f http://localhost:7860/ || exit 1
86
+
87
+ # Start supervisor
88
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
README_HF_SPACE.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: FastVLM Screen Observer
3
+ emoji: ๐Ÿ–ฅ๏ธ๐Ÿ‘๏ธ
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: docker
7
+ sdk_version: "3.9"
8
+ app_port: 7860
9
+ pinned: false
10
+ license: mit
11
+ models:
12
+ - apple/FastVLM-7B
13
+ suggested_hardware: t4-small
14
+ custom_headers:
15
+ cross-origin-embedder-policy: require-corp
16
+ cross-origin-opener-policy: same-origin
17
+ ---
18
+
19
+ # FastVLM Screen Observer ๐Ÿ–ฅ๏ธ๐Ÿ‘๏ธ
20
+
21
+ Real-time screen observation and analysis using Apple's FastVLM-7B model, optimized for low-RAM systems (3-8GB).
22
+
23
+ ## Features
24
+ - ๐ŸŽฏ Real-time screen capture and analysis
25
+ - ๐Ÿค– FastVLM-7B vision-language model integration
26
+ - ๐Ÿ” UI element detection
27
+ - ๐Ÿ“ Text extraction from screenshots
28
+ - โš ๏ธ Risk detection for security concerns
29
+ - ๐ŸŽฎ Browser automation demo
30
+ - ๐Ÿ’พ Export logs and captured frames
31
+ - ๐Ÿš€ Optimized for 3-8GB RAM with 4-bit quantization
32
+
33
+ ## How to Use
34
+ 1. Click "Capture Screen" to analyze your current screen
35
+ 2. Enable "Auto Capture" for continuous monitoring
36
+ 3. Use "Run Demo" to see browser automation
37
+ 4. Export logs as ZIP archive
38
+
39
+ ## Model Information
40
+ - **Model**: Apple FastVLM-7B
41
+ - **Optimization**: Extreme memory optimization with 4-bit quantization
42
+ - **Memory**: Runs on 3-8GB RAM systems
43
+ - **Device**: Supports CPU, CUDA, and MPS (Apple Silicon)
44
+
45
+ ## API Endpoints
46
+ - `GET /api/` - Status check
47
+ - `POST /api/analyze` - Screen analysis
48
+ - `POST /api/demo` - Automation demo
49
+ - `GET /api/export` - Export logs
50
+ - `GET /api/logs/stream` - Stream logs via SSE
51
+
52
+ ## GitHub Repository
53
+ https://github.com/crosse712/fastvlm-screen-observer
54
+
55
+ ---
56
+ Built with โค๏ธ using FastAPI, React, and FastVLM-7B
frontend/src/App.jsx CHANGED
@@ -3,7 +3,7 @@ import axios from 'axios'
3
  import ScreenCapture from './ScreenCapture'
4
  import './App.css'
5
 
6
- const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8000'
7
 
8
  function App() {
9
  const [isCapturing, setIsCapturing] = useState(false)
 
3
  import ScreenCapture from './ScreenCapture'
4
  import './App.css'
5
 
6
+ const API_BASE = import.meta.env.VITE_API_URL || (window.location.hostname === 'localhost' ? 'http://localhost:8000' : '/api')
7
 
8
  function App() {
9
  const [isCapturing, setIsCapturing] = useState(false)