radames commited on
Commit
9abe28f
1 Parent(s): e1c0fad
.gitignore ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+
10
+ # Ignore files for PNPM, NPM and YARN
11
+ pnpm-lock.yaml
12
+ package-lock.json
13
+ yarn.lock
14
+ venv/
15
+ __pycache__/
16
+ flagged/
17
+ /static
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nikolaik/python-nodejs:python3.9-nodejs18
2
+
3
+ # Git LFS
4
+ RUN apt-get update && apt-get install -y git-lfs
5
+ RUN git lfs install
6
+
7
+ # Default Debian packages
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ libssl-dev \
11
+ wget \
12
+ ffmpeg \
13
+ libsm6 \
14
+ libxrender-dev \
15
+ ffmpeg \
16
+ libsm6 \
17
+ libxext6 \
18
+ cmake \
19
+ libgl1-mesa-glx
20
+
21
+ WORKDIR /code
22
+
23
+ COPY . .
24
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
25
+
26
+ WORKDIR /code/frontend
27
+
28
+ RUN npm install && npm run build
29
+
30
+ WORKDIR /code
31
+
32
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Docker Sveltekit
3
  emoji: 🐠
4
  colorFrom: red
5
  colorTo: blue
 
1
  ---
2
+ title: Docker Sveltekit Pre-rendered
3
  emoji: 🐠
4
  colorFrom: red
5
  colorTo: blue
frontend/.eslintignore ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+
10
+ # Ignore files for PNPM, NPM and YARN
11
+ pnpm-lock.yaml
12
+ package-lock.json
13
+ yarn.lock
frontend/.eslintrc.cjs ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
5
+ plugins: ['svelte3', '@typescript-eslint'],
6
+ ignorePatterns: ['*.cjs'],
7
+ overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
8
+ settings: {
9
+ 'svelte3/typescript': () => require('typescript')
10
+ },
11
+ parserOptions: {
12
+ sourceType: 'module',
13
+ ecmaVersion: 2020
14
+ },
15
+ env: {
16
+ browser: true,
17
+ es2017: true,
18
+ node: true
19
+ }
20
+ };
frontend/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
frontend/.npmrc ADDED
@@ -0,0 +1 @@
 
 
1
+ engine-strict=true
frontend/.prettierignore ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+
10
+ # Ignore files for PNPM, NPM and YARN
11
+ pnpm-lock.yaml
12
+ package-lock.json
13
+ yarn.lock
frontend/.prettierrc ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "useTabs": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "none",
5
+ "printWidth": 100,
6
+ "plugins": ["prettier-plugin-svelte"],
7
+ "pluginSearchDirs": ["."],
8
+ "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
9
+ }
frontend/README.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # create-svelte
2
+
3
+ Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
4
+
5
+ ## Creating a project
6
+
7
+ If you're seeing this, you've probably already done this step. Congrats!
8
+
9
+ ```bash
10
+ # create a new project in the current directory
11
+ npm create svelte@latest
12
+
13
+ # create a new project in my-app
14
+ npm create svelte@latest my-app
15
+ ```
16
+
17
+ ## Developing
18
+
19
+ Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20
+
21
+ ```bash
22
+ npm run dev
23
+
24
+ # or start the server and open the app in a new browser tab
25
+ npm run dev -- --open
26
+ ```
27
+
28
+ ## Building
29
+
30
+ To create a production version of your app:
31
+
32
+ ```bash
33
+ npm run build
34
+ ```
35
+
36
+ You can preview the production build with `npm run preview`.
37
+
38
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
frontend/package.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "frontend",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "vite dev",
7
+ "build": "vite build",
8
+ "preview": "vite preview",
9
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
10
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
11
+ "lint": "prettier --plugin-search-dir . --check . && eslint .",
12
+ "format": "prettier --plugin-search-dir . --write ."
13
+ },
14
+ "devDependencies": {
15
+ "@sveltejs/adapter-static": "^1.0.0-next.47",
16
+ "@sveltejs/kit": "next",
17
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
18
+ "@typescript-eslint/parser": "^5.27.0",
19
+ "autoprefixer": "^10.4.13",
20
+ "eslint": "^8.16.0",
21
+ "eslint-config-prettier": "^8.3.0",
22
+ "eslint-plugin-svelte3": "^4.0.0",
23
+ "postcss": "^8.4.18",
24
+ "prettier": "^2.6.2",
25
+ "prettier-plugin-svelte": "^2.7.0",
26
+ "svelte": "^3.44.0",
27
+ "svelte-check": "^2.7.1",
28
+ "svelte-preprocess": "^4.10.7",
29
+ "tailwindcss": "^3.2.1",
30
+ "tslib": "^2.3.1",
31
+ "typescript": "^4.7.4",
32
+ "vite": "^3.1.0"
33
+ },
34
+ "type": "module"
35
+ }
frontend/postcss.config.cjs ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ }
frontend/src/app.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
frontend/src/app.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ // See https://kit.svelte.dev/docs/types#app
2
+ // for information about these interfaces
3
+ // and what to do when importing types
4
+ declare namespace App {
5
+ // interface Locals {}
6
+ // interface PageData {}
7
+ // interface Error {}
8
+ // interface Platform {}
9
+ }
frontend/src/app.html ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%sveltekit.assets%/favicon.png" />
6
+ <meta name="viewport" content="width=device-width" />
7
+ %sveltekit.head%
8
+ </head>
9
+ <body>
10
+ <div>%sveltekit.body%</div>
11
+ </body>
12
+ </html>
frontend/src/routes/+layout.svelte ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <script>
2
+ import "../app.css";
3
+ </script>
4
+
5
+ <slot />
frontend/src/routes/+layout.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export const prerender = true;
frontend/src/routes/+page.svelte ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ <h1 class="text-3xl font-bold underline">
2
+ Hello world!
3
+ </h1>
frontend/static/favicon.png ADDED
frontend/svelte.config.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import adapter from '@sveltejs/adapter-static';
2
+ import preprocess from 'svelte-preprocess';
3
+
4
+ /** @type {import('@sveltejs/kit').Config} */
5
+ const config = {
6
+ // Consult https://github.com/sveltejs/svelte-preprocess
7
+ // for more information about preprocessors
8
+ preprocess: preprocess({
9
+ postcss: true,
10
+ }
11
+ ),
12
+
13
+ kit: {
14
+ adapter: adapter({
15
+ // default options are shown. On some platforms
16
+ // these options are set automatically — see below
17
+ pages: '../static',
18
+ assets: '../static',
19
+ fallback: null,
20
+ precompress: false,
21
+ strict: true
22
+ })
23
+
24
+ }
25
+ };
26
+
27
+ export default config;
frontend/tailwind.config.cjs ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: ['./src/**/*.{html,js,svelte,ts}'],
4
+ theme: {
5
+ extend: {}
6
+ },
7
+ plugins: []
8
+ };
frontend/tsconfig.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "extends": "./.svelte-kit/tsconfig.json",
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "checkJs": true,
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "resolveJsonModule": true,
9
+ "skipLibCheck": true,
10
+ "sourceMap": true,
11
+ "strict": true
12
+ }
13
+ // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
14
+ //
15
+ // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
16
+ // from the referenced tsconfig.json - TypeScript does not merge them in
17
+ }
frontend/vite.config.ts ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ import { sveltekit } from '@sveltejs/kit/vite';
2
+ import type { UserConfig } from 'vite';
3
+
4
+ const config: UserConfig = {
5
+ plugins: [sveltekit()]
6
+ };
7
+
8
+ export default config;
main.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastapi import FastAPI
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+
6
+ app = FastAPI()
7
+
8
+ blocks = gr.Blocks().queue()
9
+
10
+ with blocks as demo:
11
+ with gr.Row():
12
+ with gr.Column(scale=3, min_width=270):
13
+ text_input = gr.Textbox(
14
+ label="Input", placeholder="input your text here", lines=4
15
+ )
16
+ with gr.Column(scale=2, min_width=150):
17
+ text_output = gr.Textbox(
18
+ label="Output", lines=4
19
+ )
20
+
21
+ run_button = gr.Button("Run")
22
+
23
+ run_button.click(
24
+ fn=lambda x: x,
25
+ inputs=[text_input],
26
+ outputs=[text_output],
27
+ )
28
+
29
+ blocks.config['dev_mode'] = False
30
+
31
+ app = gr.mount_gradio_app(app, blocks, "/gradio",
32
+ gradio_api_url="http://0.0.0.0:8000/gradio/")
33
+
34
+
35
+ @ app.get('/api/your_api')
36
+ async def your_api():
37
+ return {"message": "Hello World"}
38
+
39
+
40
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
41
+
42
+ origins = ["*"]
43
+
44
+ app.add_middleware(
45
+ CORSMiddleware,
46
+ allow_origins=origins,
47
+ allow_credentials=True,
48
+ allow_methods=["*"],
49
+ allow_headers=["*"],
50
+ )
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ fastapi
3
+ uvicorn