Spaces:
Sleeping
Sleeping
Commit
·
5f4d02f
1
Parent(s):
902f89c
Use lock
Browse files- processing.py +9 -6
processing.py
CHANGED
@@ -13,6 +13,7 @@ import requests
|
|
13 |
from pathlib import Path
|
14 |
from screenshot import get_screen_shot
|
15 |
import boto3
|
|
|
16 |
|
17 |
|
18 |
class SpaceData(TypedDict):
|
@@ -39,6 +40,7 @@ s3_client = boto3.client(
|
|
39 |
aws_access_key_id=os.getenv("AWS_ACCESS_KEY"),
|
40 |
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
|
41 |
)
|
|
|
42 |
|
43 |
|
44 |
api = huggingface_hub.HfApi(token=os.getenv("HF_TOKEN"))
|
@@ -66,12 +68,13 @@ def get_info(space_name: SpaceInfo) -> SpaceData | None:
|
|
66 |
light_file = str(screen_shot_dir / Path(img_id + "_light.jpg"))
|
67 |
dark_file = str(screen_shot_dir / Path(img_id + "_dark.jpg"))
|
68 |
if status == "RUNNING":
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
s3_client.upload_file(
|
76 |
light_file,
|
77 |
"gradio-theme-screenshots",
|
|
|
13 |
from pathlib import Path
|
14 |
from screenshot import get_screen_shot
|
15 |
import boto3
|
16 |
+
from threading import Lock
|
17 |
|
18 |
|
19 |
class SpaceData(TypedDict):
|
|
|
40 |
aws_access_key_id=os.getenv("AWS_ACCESS_KEY"),
|
41 |
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
|
42 |
)
|
43 |
+
lock = Lock()
|
44 |
|
45 |
|
46 |
api = huggingface_hub.HfApi(token=os.getenv("HF_TOKEN"))
|
|
|
68 |
light_file = str(screen_shot_dir / Path(img_id + "_light.jpg"))
|
69 |
dark_file = str(screen_shot_dir / Path(img_id + "_dark.jpg"))
|
70 |
if status == "RUNNING":
|
71 |
+
with lock:
|
72 |
+
get_screen_shot(
|
73 |
+
f"https://{space_info.subdomain}.hf.space?__theme=light", 10, light_file
|
74 |
+
)
|
75 |
+
get_screen_shot(
|
76 |
+
f"https://{space_info.subdomain}.hf.space?__theme=dark", 10, dark_file
|
77 |
+
)
|
78 |
s3_client.upload_file(
|
79 |
light_file,
|
80 |
"gradio-theme-screenshots",
|