Update app.py
Browse files
app.py
CHANGED
@@ -50,6 +50,7 @@ def update_game(inp):
|
|
50 |
return game_fn(sky=sky)
|
51 |
|
52 |
def sky_fn(inp):
|
|
|
53 |
rand = random.randint(1,200)
|
54 |
for i in range(rand):
|
55 |
inp+=" "
|
@@ -72,6 +73,7 @@ def sky_fn(inp):
|
|
72 |
return outp,out_url
|
73 |
|
74 |
def star_fn(inp):
|
|
|
75 |
rand = random.randint(1,200)
|
76 |
for i in range(rand):
|
77 |
inp+=" "
|
@@ -86,6 +88,7 @@ def star_fn(inp):
|
|
86 |
return out,out_url
|
87 |
|
88 |
def enemy_fn(inp):
|
|
|
89 |
rand = random.randint(1,200)
|
90 |
for i in range(rand):
|
91 |
inp+=" "
|
@@ -99,7 +102,11 @@ def enemy_fn(inp):
|
|
99 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
100 |
return out,out_url
|
101 |
|
102 |
-
def save_game(name,score):
|
|
|
|
|
|
|
|
|
103 |
user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
|
104 |
timestamp=str(datetime.datetime.now())
|
105 |
timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
|
@@ -121,7 +128,7 @@ def save_game(name,score):
|
|
121 |
pass
|
122 |
try:
|
123 |
api.upload_file(
|
124 |
-
path_or_fileobj=
|
125 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
|
126 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
127 |
token=token_self,
|
@@ -132,7 +139,7 @@ def save_game(name,score):
|
|
132 |
pass
|
133 |
try:
|
134 |
api.upload_file(
|
135 |
-
path_or_fileobj=
|
136 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
|
137 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
138 |
token=token_self,
|
@@ -143,7 +150,7 @@ def save_game(name,score):
|
|
143 |
pass
|
144 |
try:
|
145 |
api.upload_file(
|
146 |
-
path_or_fileobj=
|
147 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
|
148 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
149 |
token=token_self,
|
@@ -348,7 +355,7 @@ with gr.Blocks() as app:
|
|
348 |
|
349 |
get_high_score_btn.click(get_high_score,None,score_html)
|
350 |
get_score.click(return_score,score,[score],_js=score_js)
|
351 |
-
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score],message)
|
352 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game).then(get_high_score,None,score_html)
|
353 |
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
354 |
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|
|
|
50 |
return game_fn(sky=sky)
|
51 |
|
52 |
def sky_fn(inp):
|
53 |
+
uid=uuid.uuid4()
|
54 |
rand = random.randint(1,200)
|
55 |
for i in range(rand):
|
56 |
inp+=" "
|
|
|
73 |
return outp,out_url
|
74 |
|
75 |
def star_fn(inp):
|
76 |
+
uid=uuid.uuid4()
|
77 |
rand = random.randint(1,200)
|
78 |
for i in range(rand):
|
79 |
inp+=" "
|
|
|
88 |
return out,out_url
|
89 |
|
90 |
def enemy_fn(inp):
|
91 |
+
uid=uuid.uuid4()
|
92 |
rand = random.randint(1,200)
|
93 |
for i in range(rand):
|
94 |
inp+=" "
|
|
|
102 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
103 |
return out,out_url
|
104 |
|
105 |
+
def save_game(name,score,sky_im,star_im,enemy_im):
|
106 |
+
sky_im=sky_im.split("app/",1)[1]
|
107 |
+
star_im=star_im.split("app/",1)[1]
|
108 |
+
#sky_im=sky_im.split("app/",1)[1]
|
109 |
+
print(star_im)
|
110 |
user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
|
111 |
timestamp=str(datetime.datetime.now())
|
112 |
timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
|
|
|
128 |
pass
|
129 |
try:
|
130 |
api.upload_file(
|
131 |
+
path_or_fileobj=sky_im,
|
132 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
|
133 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
134 |
token=token_self,
|
|
|
139 |
pass
|
140 |
try:
|
141 |
api.upload_file(
|
142 |
+
path_or_fileobj=star_im,
|
143 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
|
144 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
145 |
token=token_self,
|
|
|
150 |
pass
|
151 |
try:
|
152 |
api.upload_file(
|
153 |
+
path_or_fileobj=enemy_im.split("app/",1)[1],
|
154 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
|
155 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
156 |
token=token_self,
|
|
|
355 |
|
356 |
get_high_score_btn.click(get_high_score,None,score_html)
|
357 |
get_score.click(return_score,score,[score],_js=score_js)
|
358 |
+
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score,out_sky_url,out_star_url,out_enemy_url],message)
|
359 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game).then(get_high_score,None,score_html)
|
360 |
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
361 |
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|