Update app.py
Browse files
app.py
CHANGED
|
@@ -88,7 +88,7 @@ def star_fn(inp):
|
|
| 88 |
outrs.save(f"{uid}_star.png")
|
| 89 |
out_file = os.path.abspath(f"{uid}_star.png")
|
| 90 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
| 91 |
-
return
|
| 92 |
|
| 93 |
def enemy_fn(inp):
|
| 94 |
rand = random.randint(1,200)
|
|
@@ -102,9 +102,9 @@ def enemy_fn(inp):
|
|
| 102 |
outrs.save(f"{uid}_enemy.png")
|
| 103 |
out_file = os.path.abspath(f"{uid}_enemy.png")
|
| 104 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
| 105 |
-
return
|
| 106 |
|
| 107 |
-
def save_game(name,score
|
| 108 |
user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
|
| 109 |
timestamp=str(datetime.datetime.now())
|
| 110 |
timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
|
|
@@ -129,7 +129,7 @@ def save_game(name,score,background_img,star_img,enemy_img,platform_img,dude_img
|
|
| 129 |
print(timestamp)
|
| 130 |
try:
|
| 131 |
api.upload_file(
|
| 132 |
-
path_or_fileobj=
|
| 133 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
|
| 134 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 135 |
token=token_self,
|
|
@@ -140,7 +140,7 @@ def save_game(name,score,background_img,star_img,enemy_img,platform_img,dude_img
|
|
| 140 |
pass
|
| 141 |
try:
|
| 142 |
api.upload_file(
|
| 143 |
-
path_or_fileobj=
|
| 144 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
|
| 145 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 146 |
token=token_self,
|
|
@@ -151,7 +151,7 @@ def save_game(name,score,background_img,star_img,enemy_img,platform_img,dude_img
|
|
| 151 |
pass
|
| 152 |
try:
|
| 153 |
api.upload_file(
|
| 154 |
-
path_or_fileobj=
|
| 155 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
|
| 156 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 157 |
token=token_self,
|
|
@@ -288,7 +288,7 @@ with gr.Blocks() as app:
|
|
| 288 |
def return_score(text):
|
| 289 |
return text
|
| 290 |
get_score.click(return_score,score,[score],_js=score_js)
|
| 291 |
-
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score
|
| 292 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
| 293 |
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
| 294 |
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|
|
|
|
| 88 |
outrs.save(f"{uid}_star.png")
|
| 89 |
out_file = os.path.abspath(f"{uid}_star.png")
|
| 90 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
| 91 |
+
return out,out_url
|
| 92 |
|
| 93 |
def enemy_fn(inp):
|
| 94 |
rand = random.randint(1,200)
|
|
|
|
| 102 |
outrs.save(f"{uid}_enemy.png")
|
| 103 |
out_file = os.path.abspath(f"{uid}_enemy.png")
|
| 104 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
| 105 |
+
return out,out_url
|
| 106 |
|
| 107 |
+
def save_game(name,score):
|
| 108 |
user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
|
| 109 |
timestamp=str(datetime.datetime.now())
|
| 110 |
timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
|
|
|
|
| 129 |
print(timestamp)
|
| 130 |
try:
|
| 131 |
api.upload_file(
|
| 132 |
+
path_or_fileobj=f"{uid}_sky.png",
|
| 133 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
|
| 134 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 135 |
token=token_self,
|
|
|
|
| 140 |
pass
|
| 141 |
try:
|
| 142 |
api.upload_file(
|
| 143 |
+
path_or_fileobj=f"{uid}_star.png",
|
| 144 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
|
| 145 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 146 |
token=token_self,
|
|
|
|
| 151 |
pass
|
| 152 |
try:
|
| 153 |
api.upload_file(
|
| 154 |
+
path_or_fileobj=f"{uid}_enemy.png",
|
| 155 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
|
| 156 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 157 |
token=token_self,
|
|
|
|
| 288 |
def return_score(text):
|
| 289 |
return text
|
| 290 |
get_score.click(return_score,score,[score],_js=score_js)
|
| 291 |
+
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score],message)
|
| 292 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
| 293 |
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
| 294 |
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|