Spaces:
Running
Running
Commit ·
373fbfb
1
Parent(s): 60943f3
Update hugging face settings
Browse files- Dockerfile +15 -25
- frontend/src/App.tsx +1 -1
- frontend/src/pyodide.worker.ts +3 -2
- frontend/vite.config.ts +1 -0
Dockerfile
CHANGED
|
@@ -1,30 +1,20 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM node:
|
| 3 |
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
COPY --chown=1000 frontend .
|
| 9 |
-
|
| 10 |
-
RUN npm install
|
| 11 |
-
RUN npm run build
|
| 12 |
-
|
| 13 |
-
# --- Stage 2: Final Python Image ---
|
| 14 |
-
FROM python:3.13-slim
|
| 15 |
WORKDIR /app
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
ENV PATH=/app/.local/bin:$PATH
|
| 20 |
-
USER 1000
|
| 21 |
-
|
| 22 |
-
COPY --chown=1000 --from=build-frontend /app/dist /app/frontend/dist
|
| 23 |
-
|
| 24 |
-
COPY --chown=1000 backend /app/backend
|
| 25 |
-
|
| 26 |
-
EXPOSE 7860
|
| 27 |
-
WORKDIR /app/backend
|
| 28 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Step 1: Build your app
|
| 2 |
+
FROM node:20 AS builder
|
| 3 |
WORKDIR /app
|
| 4 |
+
COPY frontend/package*.json ./frontend/
|
| 5 |
+
RUN cd frontend && npm install
|
| 6 |
+
COPY . .
|
| 7 |
+
RUN cd frontend && npm run build
|
| 8 |
|
| 9 |
+
# Step 2: Serve it with npx
|
| 10 |
+
FROM node:20-slim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
WORKDIR /app
|
| 12 |
+
# Only copy the built files from the builder
|
| 13 |
+
COPY --from=builder /app/frontend/dist ./dist
|
| 14 |
|
| 15 |
+
# Install the server tool
|
| 16 |
+
RUN npm install -g serve
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Serve the 'dist' folder on the correct Hugging Face port
|
| 19 |
+
# -s flag handles Single Page App routing (important for React)
|
| 20 |
+
CMD ["serve", "-s", "dist", "-l", "7860"]
|
frontend/src/App.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import {
|
| 2 |
import OptimizationPlot from "./OptimizationPlot.tsx";
|
| 3 |
import Sidebar from "./Sidebar.tsx";
|
| 4 |
import type { Settings } from "./types.ts";
|
|
|
|
| 1 |
+
import { useState } from "react";
|
| 2 |
import OptimizationPlot from "./OptimizationPlot.tsx";
|
| 3 |
import Sidebar from "./Sidebar.tsx";
|
| 4 |
import type { Settings } from "./types.ts";
|
frontend/src/pyodide.worker.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
//
|
| 2 |
-
import { loadPyodide } from "https://cdn.jsdelivr.net/pyodide/v0.26.1/full/pyodide.mjs";
|
| 3 |
|
| 4 |
// @ts-ignore
|
| 5 |
import managerCode from "../../backend/src/optimization_manager.py?raw";
|
|
@@ -10,6 +9,8 @@ let pyodide: any = null;
|
|
| 10 |
let manager: any = null;
|
| 11 |
|
| 12 |
async function init() {
|
|
|
|
|
|
|
| 13 |
pyodide = await loadPyodide({
|
| 14 |
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.1/full/"
|
| 15 |
});
|
|
|
|
| 1 |
+
const PYODIDE_URL = "https://cdn.jsdelivr.net/pyodide/v0.26.1/full/pyodide.mjs";
|
|
|
|
| 2 |
|
| 3 |
// @ts-ignore
|
| 4 |
import managerCode from "../../backend/src/optimization_manager.py?raw";
|
|
|
|
| 9 |
let manager: any = null;
|
| 10 |
|
| 11 |
async function init() {
|
| 12 |
+
const { loadPyodide } = await import(/* @vite-ignore */ PYODIDE_URL);
|
| 13 |
+
|
| 14 |
pyodide = await loadPyodide({
|
| 15 |
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.1/full/"
|
| 16 |
});
|
frontend/vite.config.ts
CHANGED
|
@@ -4,6 +4,7 @@ import tailwindcss from '@tailwindcss/vite'
|
|
| 4 |
|
| 5 |
// https://vite.dev/config/
|
| 6 |
export default defineConfig({
|
|
|
|
| 7 |
plugins: [
|
| 8 |
react(),
|
| 9 |
tailwindcss(),
|
|
|
|
| 4 |
|
| 5 |
// https://vite.dev/config/
|
| 6 |
export default defineConfig({
|
| 7 |
+
base: './',
|
| 8 |
plugins: [
|
| 9 |
react(),
|
| 10 |
tailwindcss(),
|