maartenbreddels commited on
Commit
c24f025
·
1 Parent(s): fed5513

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -25
app.py CHANGED
@@ -1,30 +1,36 @@
1
  """This files enables serving Panel apps on Hugging Face Spaces"""
2
- import os
3
- from subprocess import Popen
4
 
5
 
6
- print(os.environ)
7
- # CONFIGURE YOUR SETTINGS HERE
 
 
 
 
 
 
 
8
 
9
- # Space separated list of .py or .ipynb files to serve
10
- APP = "solara.website.pages"
11
- # NORMALLY NO NEED TO CHANGE THE BELOW
12
- PORT = os.environ.get("PORT", "7860")
13
- ADDRESS = "0.0.0.0"
14
- command = [
15
- "solara",
16
- "run",
17
- APP,
18
- "--port",
19
- PORT,
20
- "--host",
21
- ADDRESS,
22
- "--log-level-uvicorn",
23
- "debug"
24
- ]
25
- #if os.name != "nt":
26
- # command = command + ["--num-procs", "4", "--num-threads", "4"]
27
 
28
- print(" ".join(command))
29
- worker = Popen(command)
30
- worker.wait()
 
 
 
 
 
 
 
 
 
 
 
1
  """This files enables serving Panel apps on Hugging Face Spaces"""
2
+ import solara
 
3
 
4
 
5
+ @solara.component
6
+ def Page():
7
+ clicks, set_clicks = solara.use_state(0)
8
+ return solara.VBox(
9
+ [
10
+ solara.Button("Click me", on_click=lambda: set_clicks(clicks + 1)),
11
+ solara.Text(f"Clicks: {clicks}"),
12
+ ]
13
+ )
14
 
15
+ def run(*,port=8877, host=None):
16
+ import os
17
+ if host is None:
18
+ host = os.environ.get("HOST")
19
+ if host is None:
20
+ host = os.getenv("GRADIO_SERVER_NAME")
21
+ if host is None:
22
+ host = "localhost"
 
 
 
 
 
 
 
 
 
 
23
 
24
+ os.environ["SOLARA_APP"] = "__main__"
25
+
26
+ import uvicorn
27
+ from .server.starlette import app as asgi_app
28
+
29
+ config = uvicorn.Config(
30
+ app=asgi_app,
31
+ host=host,
32
+ port=port,
33
+ )
34
+ server = uvicorn.Server(config=config)
35
+ server.run()
36
+ run()