Deploy app!
Browse files- Dockerfile +1 -1
- README.md +4 -110
- {default_app → app/}/__init__.py +0 -0
- app//app.py +34 -0
- assets/{favicon.ico → /favicon.ico} +0 -0
- default_app/default_app.py +0 -58
- pcconfig_docker.py +2 -2
Dockerfile
CHANGED
|
@@ -49,7 +49,7 @@ RUN python -c "from pathlib import Path; from pynecone.utils import setup_fronte
|
|
| 49 |
|
| 50 |
# Copy existing project
|
| 51 |
COPY --chown=pn pcconfig_docker.py pcconfig.py
|
| 52 |
-
COPY --chown=pn
|
| 53 |
COPY --chown=pn assets assets
|
| 54 |
|
| 55 |
# Re-init frontend (if new deps from project)
|
|
|
|
| 49 |
|
| 50 |
# Copy existing project
|
| 51 |
COPY --chown=pn pcconfig_docker.py pcconfig.py
|
| 52 |
+
COPY --chown=pn app app
|
| 53 |
COPY --chown=pn assets assets
|
| 54 |
|
| 55 |
# Re-init frontend (if new deps from project)
|
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🐿️
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: blue
|
|
@@ -9,114 +9,8 @@ pinned: false
|
|
| 9 |
license: mit
|
| 10 |
duplicated_from: Wauplin/pynecone-on-spaces-template
|
| 11 |
---
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
If you encounter any issue, please let us know by creating a discussion in our [Community tab](https://huggingface.co/spaces/Wauplin/pynecone-on-spaces-template/discussions).
|
| 18 |
-
|
| 19 |
-
### Instructions:
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
#### 1. Install deployment tool
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
Install the deployment script [from source](https://github.com/Wauplin/pynecone-on-spaces):
|
| 26 |
-
|
| 27 |
-
```
|
| 28 |
-
pip install git+https://github.com/Wauplin/pynecone-on-spaces
|
| 29 |
-
```
|
| 30 |
-
|
| 31 |
-
#### 2. (optional) Login to Huggingface
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
If you don't already have an account, please [register](https://huggingface.co/join) to HF.
|
| 35 |
-
|
| 36 |
-
You will next need to [setup a token](https://huggingface.co/settings/tokens) with `WRITE` permissions.
|
| 37 |
-
|
| 38 |
-
Once you have it, login your machine to your account by running the following command in your terminal:
|
| 39 |
-
|
| 40 |
-
```bash
|
| 41 |
-
huggingface-cli login
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
#### 3. Deploy 🚀
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
Simply deploy your pynecone app:
|
| 48 |
-
|
| 49 |
-
```bash
|
| 50 |
-
huggingface-pynecone deploy
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
**Output:**
|
| 54 |
-
```txt
|
| 55 |
-
New Space created: https://huggingface.co/spaces/Wauplin/clock
|
| 56 |
-
README.md file not found locally. Adapting the existing remote one.
|
| 57 |
-
Setup pcconfig.py
|
| 58 |
-
Setup Dockerfile
|
| 59 |
-
Sync requirements.txt
|
| 60 |
-
Sync assets/ folder
|
| 61 |
-
Sync app folder
|
| 62 |
-
Your app has been successfully deployed!
|
| 63 |
-
Check it out: https://Wauplin-clock.hf.space
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
The name of your repository will be derived from the app name defined in your `pcconfig.py` file.
|
| 67 |
-
|
| 68 |
-
For more flexibility, you can specify some arguments:
|
| 69 |
-
|
| 70 |
-
```bash
|
| 71 |
-
huggingface-pynecone deploy --pcconfig_path="path/to/pcconfig.py" --private --token="hf_xxx"
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
#### 4. Sync changes
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
Your project is now hosted in a versioned repository on Huggingface.
|
| 78 |
-
|
| 79 |
-
You can decide to clone the repository and push your changes as you would do with any project.
|
| 80 |
-
Please make sure to not break anything in `README.md` (metadata), `Dockerfile` and `pcconfig_docker.py`.
|
| 81 |
-
|
| 82 |
-
Otherwise, you can make changes to your existing project and push your changes using the same command:
|
| 83 |
-
|
| 84 |
-
```bash
|
| 85 |
-
huggingface-pynecone deploy
|
| 86 |
-
```
|
| 87 |
-
|
| 88 |
-
**Output:**
|
| 89 |
-
|
| 90 |
-
```txt
|
| 91 |
-
Repo ID: Wauplin/clock
|
| 92 |
-
Space already exist: https://huggingface.co/spaces/Wauplin/clock
|
| 93 |
-
Space already configured. Do not update README.md, Dockerfile and pcconfig.py
|
| 94 |
-
Sync requirements.txt
|
| 95 |
-
Sync assets/ folder
|
| 96 |
-
Sync app folder
|
| 97 |
-
Your app has been successfully deployed!
|
| 98 |
-
Check it out: https://Wauplin-clock.hf.space
|
| 99 |
-
```
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
### What tweaks are used to deploy you apps?
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
Some tweaks are necessary to make your Pynecone deployed on HF Spaces.
|
| 106 |
-
Everything is taken care of by the `huggingface-pynecone` CLI tool.
|
| 107 |
-
|
| 108 |
-
List of small tweaks:
|
| 109 |
-
- Running in a Docker Space means only 1 open port:
|
| 110 |
-
- We use nginx proxy to expose both frontend and backend on same port 4444
|
| 111 |
-
- Port 3000 (frontend) is redirected to localhost:4444/
|
| 112 |
-
- Port 8000 (backend) is redirected to localhost:4444/pynecone-backend
|
| 113 |
-
- Port 4444 is set in several files:
|
| 114 |
-
- `README.md`: set `app_port` parameter
|
| 115 |
-
- `nginx.conf`: define which port to listen
|
| 116 |
-
- `pcconfig.py`: monkey-patch pynecone to make it think the backend is running on port 8000 even though a different `api_url` is set
|
| 117 |
-
- `pc.Config` configuration:
|
| 118 |
-
- set env as `PROD`
|
| 119 |
-
- set `api_url` to the Space url + pynecone-backend path. Example: `"https://wauplin-pynecone-counter.hf.space/pynecone-backend"`
|
| 120 |
-
- set `port` to 3000 (frontend port)
|
| 121 |
-
- set db_url to `"sqlite:///pynecone.db"` but DB is not persisted across when the Space is reloaded (i.e.: not really a database yet)
|
| 122 |
-
- Use a `run.sh` script to start nginx before running pynecone server
|
|
|
|
| 1 |
---
|
| 2 |
+
title: App
|
| 3 |
emoji: 🐿️
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: blue
|
|
|
|
| 9 |
license: mit
|
| 10 |
duplicated_from: Wauplin/pynecone-on-spaces-template
|
| 11 |
---
|
| 12 |
+
## 🤗 Spaces x Pynecone
|
| 13 |
|
| 14 |
+
This App Space has been duplicated from the [Pynecone on Spaces template](https://huggingface.co/spaces/Wauplin/pynecone-on-spaces-template).
|
| 15 |
|
| 16 |
+
To host and deploy your own Pynecone app on 🤗 Spaces, check out [the instructions](https://huggingface.co/spaces/Wauplin/pynecone-on-spaces-template/blob/main/README.md).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{default_app → app/}/__init__.py
RENAMED
|
File without changes
|
app//app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pynecone as pc
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class State(pc.State):
|
| 5 |
+
count: int = 0
|
| 6 |
+
|
| 7 |
+
def increment(self):
|
| 8 |
+
self.count += 1
|
| 9 |
+
|
| 10 |
+
def decrement(self):
|
| 11 |
+
self.count -= 1
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def index():
|
| 15 |
+
return pc.hstack(
|
| 16 |
+
pc.button(
|
| 17 |
+
"감소",
|
| 18 |
+
color_scheme="red",
|
| 19 |
+
border_radius="1em",
|
| 20 |
+
on_click=State.decrement,
|
| 21 |
+
),
|
| 22 |
+
pc.heading(State.count, font_size="2em"),
|
| 23 |
+
pc.button(
|
| 24 |
+
"증가",
|
| 25 |
+
color_scheme="green",
|
| 26 |
+
border_radius="1em",
|
| 27 |
+
on_click=State.increment,
|
| 28 |
+
),
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
app = pc.App(state=State)
|
| 33 |
+
app.add_page(index)
|
| 34 |
+
app.compile()
|
assets/{favicon.ico → /favicon.ico}
RENAMED
|
File without changes
|
default_app/default_app.py
DELETED
|
@@ -1,58 +0,0 @@
|
|
| 1 |
-
from pathlib import Path
|
| 2 |
-
|
| 3 |
-
import pynecone as pc
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
class State(pc.State):
|
| 7 |
-
count: int = 0
|
| 8 |
-
|
| 9 |
-
def increment(self):
|
| 10 |
-
self.count += 1
|
| 11 |
-
|
| 12 |
-
def decrement(self):
|
| 13 |
-
self.count -= 1
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def index():
|
| 17 |
-
return pc.center(
|
| 18 |
-
pc.vstack(
|
| 19 |
-
pc.box(
|
| 20 |
-
height="20px",
|
| 21 |
-
),
|
| 22 |
-
pc.box(
|
| 23 |
-
pc.heading("Pynecone x Spaces 🚀"),
|
| 24 |
-
),
|
| 25 |
-
pc.hstack(
|
| 26 |
-
pc.button(
|
| 27 |
-
"Decrement",
|
| 28 |
-
color_scheme="red",
|
| 29 |
-
border_radius="1em",
|
| 30 |
-
on_click=State.decrement,
|
| 31 |
-
),
|
| 32 |
-
pc.heading(State.count, font_size="2em"),
|
| 33 |
-
pc.button(
|
| 34 |
-
"Increment",
|
| 35 |
-
color_scheme="green",
|
| 36 |
-
border_radius="1em",
|
| 37 |
-
on_click=State.increment,
|
| 38 |
-
),
|
| 39 |
-
),
|
| 40 |
-
pc.box(
|
| 41 |
-
height="50px",
|
| 42 |
-
),
|
| 43 |
-
pc.box(
|
| 44 |
-
# Hacky way to append README content to the page
|
| 45 |
-
pc.markdown(
|
| 46 |
-
(Path(__file__).parent.parent / "README.md")
|
| 47 |
-
.read_text()
|
| 48 |
-
.split("---")[-1]
|
| 49 |
-
.strip()
|
| 50 |
-
)
|
| 51 |
-
),
|
| 52 |
-
)
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
app = pc.App(state=State)
|
| 57 |
-
app.add_page(index)
|
| 58 |
-
app.compile()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pcconfig_docker.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import pynecone as pc
|
| 2 |
|
| 3 |
config = pc.Config(
|
| 4 |
-
app_name="
|
| 5 |
db_url="sqlite:///pynecone.db",
|
| 6 |
-
api_url="https://
|
| 7 |
env=pc.Env.PROD,
|
| 8 |
)
|
| 9 |
|
|
|
|
| 1 |
import pynecone as pc
|
| 2 |
|
| 3 |
config = pc.Config(
|
| 4 |
+
app_name="app",
|
| 5 |
db_url="sqlite:///pynecone.db",
|
| 6 |
+
api_url="https://martinii-app.hf.space/pynecone-backend",
|
| 7 |
env=pc.Env.PROD,
|
| 8 |
)
|
| 9 |
|