Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from rembg import remove as rm
|
|
| 9 |
import datetime
|
| 10 |
from huggingface_hub import (HfApi)
|
| 11 |
import uuid
|
|
|
|
| 12 |
uid=uuid.uuid4()
|
| 13 |
proc1=diff
|
| 14 |
proc2=diff
|
|
@@ -108,25 +109,46 @@ def save_game(background_img,star_img,enemy_img,platform_img,dude_img):
|
|
| 108 |
lod=[]
|
| 109 |
pass
|
| 110 |
timestamp=str(datetime.datetime.now())
|
|
|
|
| 111 |
print(timestamp)
|
| 112 |
try:
|
| 113 |
api.upload_file(
|
| 114 |
path_or_fileobj=background_img,
|
| 115 |
-
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{
|
| 116 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 117 |
token=token_self,
|
| 118 |
repo_type="dataset",
|
| 119 |
)
|
| 120 |
-
#os.remove("tmp1.json")
|
| 121 |
-
|
| 122 |
except Exception as e:
|
| 123 |
print (e)
|
| 124 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
block = {'index': len(lod) + 1,
|
| 126 |
'timestamp': timestamp,
|
| 127 |
-
'background_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/background/{
|
| 128 |
-
'star_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/star/{star_img
|
| 129 |
-
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/enemy/{enemy_img
|
| 130 |
#'platform_url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{platform_img}',
|
| 131 |
#'dude_url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{dude_img}',
|
| 132 |
}
|
|
|
|
| 9 |
import datetime
|
| 10 |
from huggingface_hub import (HfApi)
|
| 11 |
import uuid
|
| 12 |
+
import json
|
| 13 |
uid=uuid.uuid4()
|
| 14 |
proc1=diff
|
| 15 |
proc2=diff
|
|
|
|
| 109 |
lod=[]
|
| 110 |
pass
|
| 111 |
timestamp=str(datetime.datetime.now())
|
| 112 |
+
timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
|
| 113 |
print(timestamp)
|
| 114 |
try:
|
| 115 |
api.upload_file(
|
| 116 |
path_or_fileobj=background_img,
|
| 117 |
+
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{timename}-background_img.png",
|
| 118 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 119 |
token=token_self,
|
| 120 |
repo_type="dataset",
|
| 121 |
)
|
|
|
|
|
|
|
| 122 |
except Exception as e:
|
| 123 |
print (e)
|
| 124 |
pass
|
| 125 |
+
try:
|
| 126 |
+
api.upload_file(
|
| 127 |
+
path_or_fileobj=star_img,
|
| 128 |
+
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{timename}-star_img.png",
|
| 129 |
+
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 130 |
+
token=token_self,
|
| 131 |
+
repo_type="dataset",
|
| 132 |
+
)
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print (e)
|
| 135 |
+
pass
|
| 136 |
+
try:
|
| 137 |
+
api.upload_file(
|
| 138 |
+
path_or_fileobj=enemy_img,
|
| 139 |
+
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{timename}-enemy_img.png",
|
| 140 |
+
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 141 |
+
token=token_self,
|
| 142 |
+
repo_type="dataset",
|
| 143 |
+
)
|
| 144 |
+
except Exception as e:
|
| 145 |
+
print (e)
|
| 146 |
+
pass
|
| 147 |
block = {'index': len(lod) + 1,
|
| 148 |
'timestamp': timestamp,
|
| 149 |
+
'background_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/background/{time_name}-background_img.png',
|
| 150 |
+
'star_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/star/{timename}-star_img.png',
|
| 151 |
+
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/enemy/{timename}-enemy_img.png',
|
| 152 |
#'platform_url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{platform_img}',
|
| 153 |
#'dude_url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{dude_img}',
|
| 154 |
}
|