Spaces:
Sleeping
Sleeping
refresh
Browse files- app.py +8 -0
- profile_app.py +39 -14
- supervisord.conf +8 -8
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import base64
|
2 |
import os
|
|
|
3 |
from collections import defaultdict
|
4 |
from datetime import date, datetime, timedelta
|
5 |
from io import BytesIO
|
@@ -22,6 +23,13 @@ style = Style("""
|
|
22 |
.card a:hover { text-decoration: underline; }
|
23 |
""")
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
app, rt = fast_app(html_style=(style,))
|
26 |
|
27 |
login(token=os.environ.get("HF_TOKEN"))
|
|
|
1 |
import base64
|
2 |
import os
|
3 |
+
import shutil
|
4 |
from collections import defaultdict
|
5 |
from datetime import date, datetime, timedelta
|
6 |
from io import BytesIO
|
|
|
23 |
.card a:hover { text-decoration: underline; }
|
24 |
""")
|
25 |
|
26 |
+
# delete data folder
|
27 |
+
if os.path.exists("data"):
|
28 |
+
try:
|
29 |
+
shutil.rmtree("data")
|
30 |
+
except OSError as e:
|
31 |
+
print("Error: %s : %s" % ("data", e.strerror))
|
32 |
+
|
33 |
app, rt = fast_app(html_style=(style,))
|
34 |
|
35 |
login(token=os.environ.get("HF_TOKEN"))
|
profile_app.py
CHANGED
@@ -1,27 +1,52 @@
|
|
1 |
import cProfile
|
|
|
|
|
2 |
|
|
|
3 |
from fasthtml.common import *
|
4 |
-
from starlette.testclient import TestClient
|
5 |
|
6 |
-
|
7 |
-
from app import app, weeks
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
# Test home page
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
-
# Run the profiling
|
24 |
cProfile.run("profile_app()", "profile_output.prof")
|
25 |
-
|
26 |
-
# python profile_app.py
|
27 |
-
# snakeviz profile_output.prof
|
|
|
1 |
import cProfile
|
2 |
+
import multiprocessing
|
3 |
+
import time
|
4 |
|
5 |
+
import requests
|
6 |
from fasthtml.common import *
|
|
|
7 |
|
8 |
+
from app import serve, weeks
|
|
|
9 |
|
10 |
+
PORT = 7860 # Update this to match the port your app is using
|
11 |
+
|
12 |
+
|
13 |
+
def run_server():
|
14 |
+
serve() # This should start your FastHTML app
|
15 |
|
16 |
+
|
17 |
+
def make_requests():
|
18 |
+
base_url = f"http://127.0.0.1:{PORT}"
|
19 |
|
20 |
# Test home page
|
21 |
+
try:
|
22 |
+
requests.get(f"{base_url}/")
|
23 |
+
except requests.exceptions.RequestException as e:
|
24 |
+
print(f"Error accessing home page: {e}")
|
25 |
+
|
26 |
+
# Test 5 weeks (or fewer if less than 5 weeks available)
|
27 |
+
for week in weeks[: min(5, len(weeks))]:
|
28 |
+
try:
|
29 |
+
requests.get(f"{base_url}/week/{week}")
|
30 |
+
except requests.exceptions.RequestException as e:
|
31 |
+
print(f"Error accessing week {week}: {e}")
|
32 |
|
33 |
+
# Add more requests here to cover other parts of your application
|
34 |
+
|
35 |
+
|
36 |
+
def profile_app():
|
37 |
+
server_process = multiprocessing.Process(target=run_server)
|
38 |
+
server_process.start()
|
39 |
+
|
40 |
+
# Wait for the server to start
|
41 |
+
time.sleep(5) # Increased wait time
|
42 |
+
|
43 |
+
try:
|
44 |
+
make_requests()
|
45 |
+
finally:
|
46 |
+
server_process.terminate()
|
47 |
+
server_process.join()
|
48 |
|
49 |
|
50 |
if __name__ == "__main__":
|
|
|
51 |
cProfile.run("profile_app()", "profile_output.prof")
|
52 |
+
print("Profiling complete. Run 'snakeviz profile_output.prof' to view results.")
|
|
|
|
supervisord.conf
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
[supervisord]
|
2 |
nodaemon=true
|
3 |
|
4 |
-
[program:main]
|
5 |
-
command=python main.py
|
6 |
-
stdout_logfile=/dev/stdout
|
7 |
-
stdout_logfile_maxbytes=0
|
8 |
-
stderr_logfile=/dev/stderr
|
9 |
-
stderr_logfile_maxbytes=0
|
10 |
-
autostart=true
|
11 |
-
autorestart=true
|
12 |
|
13 |
[program:app]
|
14 |
command=python app.py
|
|
|
1 |
[supervisord]
|
2 |
nodaemon=true
|
3 |
|
4 |
+
# [program:main]
|
5 |
+
# command=python main.py
|
6 |
+
# stdout_logfile=/dev/stdout
|
7 |
+
# stdout_logfile_maxbytes=0
|
8 |
+
# stderr_logfile=/dev/stderr
|
9 |
+
# stderr_logfile_maxbytes=0
|
10 |
+
# autostart=true
|
11 |
+
# autorestart=true
|
12 |
|
13 |
[program:app]
|
14 |
command=python app.py
|