Update app.py
Browse files
app.py
CHANGED
@@ -70,7 +70,7 @@ def sky_fn(inp):
|
|
70 |
out = os.path.abspath(f"{uid}_sky.png")
|
71 |
#out = os.path.abspath(outp)
|
72 |
out_url = f'https://omnibus-game-test.hf.space/file={out}'
|
73 |
-
return outp,out_url
|
74 |
|
75 |
def star_fn(inp):
|
76 |
uid=uuid.uuid4()
|
@@ -85,7 +85,7 @@ def star_fn(inp):
|
|
85 |
outrs.save(f"{uid}_star.png")
|
86 |
out_file = os.path.abspath(f"{uid}_star.png")
|
87 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
88 |
-
return out,out_url
|
89 |
|
90 |
def enemy_fn(inp):
|
91 |
uid=uuid.uuid4()
|
@@ -100,9 +100,9 @@ def enemy_fn(inp):
|
|
100 |
outrs.save(f"{uid}_enemy.png")
|
101 |
out_file = os.path.abspath(f"{uid}_enemy.png")
|
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]
|
@@ -184,7 +184,13 @@ def save_game(name,score,sky_im,star_im,enemy_im):
|
|
184 |
block = {'index': len(lod) + 1,
|
185 |
'timestamp': timestamp,
|
186 |
'game_name': game,
|
187 |
-
'score': score,
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
'background_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/background/{game}-background_img.png',
|
189 |
'star_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/star/{game}-star_img.png',
|
190 |
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/enemy/{game}-enemy_img.png',
|
@@ -214,6 +220,12 @@ def save_game(name,score,sky_im,star_im,enemy_im):
|
|
214 |
block2 = {'game_name': game,
|
215 |
'score':score,
|
216 |
'timestamp': timestamp,
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
'background_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/background/{game}-background_img.png',
|
218 |
'star_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/star/{game}-star_img.png',
|
219 |
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/enemy/{game}-enemy_img.png',
|
@@ -348,6 +360,13 @@ with gr.Blocks() as app:
|
|
348 |
text_input=gr.Textbox()
|
349 |
url_params = gr.JSON({}, visible=True, label="")
|
350 |
acc=gr.Textbox()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
|
352 |
get_high_score_btn=gr.Button()
|
353 |
def return_score(text):
|
@@ -356,11 +375,12 @@ with gr.Blocks() as app:
|
|
356 |
return None
|
357 |
get_high_score_btn.click(get_high_score,None,score_html)
|
358 |
get_score.click(return_score,score,[score],_js=score_js)
|
359 |
-
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)
|
360 |
update_game.click(refresh_frame,None,html_game).then(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game).then(get_high_score,None,score_html)
|
361 |
-
|
362 |
-
|
363 |
-
|
|
|
364 |
app.load(predict,[text_input,url_params],[text_input,html_game], _js=get_window_url_params)
|
365 |
|
366 |
#app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game)
|
|
|
70 |
out = os.path.abspath(f"{uid}_sky.png")
|
71 |
#out = os.path.abspath(outp)
|
72 |
out_url = f'https://omnibus-game-test.hf.space/file={out}'
|
73 |
+
return outp,out_url,rand
|
74 |
|
75 |
def star_fn(inp):
|
76 |
uid=uuid.uuid4()
|
|
|
85 |
outrs.save(f"{uid}_star.png")
|
86 |
out_file = os.path.abspath(f"{uid}_star.png")
|
87 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
88 |
+
return out,out_url,rand
|
89 |
|
90 |
def enemy_fn(inp):
|
91 |
uid=uuid.uuid4()
|
|
|
100 |
outrs.save(f"{uid}_enemy.png")
|
101 |
out_file = os.path.abspath(f"{uid}_enemy.png")
|
102 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
103 |
+
return out,out_url,rand
|
104 |
|
105 |
+
def save_game(name,score,sky_im,star_im,enemy_im,sky_p,star_p,enemy_p,background_s,star_s,enemy_s):
|
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]
|
|
|
184 |
block = {'index': len(lod) + 1,
|
185 |
'timestamp': timestamp,
|
186 |
'game_name': game,
|
187 |
+
'score': score,
|
188 |
+
'background_p': sky_p,
|
189 |
+
'star_p': star_p,
|
190 |
+
'enemy_p': enemy_p,
|
191 |
+
'background_s': background_s,
|
192 |
+
'star_s': star_s,
|
193 |
+
'enemy_s': enemy_s,
|
194 |
'background_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/background/{game}-background_img.png',
|
195 |
'star_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/star/{game}-star_img.png',
|
196 |
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/enemy/{game}-enemy_img.png',
|
|
|
220 |
block2 = {'game_name': game,
|
221 |
'score':score,
|
222 |
'timestamp': timestamp,
|
223 |
+
'background_p': sky_p,
|
224 |
+
'star_p': star_p,
|
225 |
+
'enemy_p': enemy_p,
|
226 |
+
'background_s': background_s,
|
227 |
+
'star_s': star_s,
|
228 |
+
'enemy_s': enemy_s,
|
229 |
'background_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/background/{game}-background_img.png',
|
230 |
'star_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/star/{game}-star_img.png',
|
231 |
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/enemy/{game}-enemy_img.png',
|
|
|
360 |
text_input=gr.Textbox()
|
361 |
url_params = gr.JSON({}, visible=True, label="")
|
362 |
acc=gr.Textbox()
|
363 |
+
with gr.Row(visible=False):
|
364 |
+
sky_p=gr.Textbox()
|
365 |
+
star_p=gr.Textbox()
|
366 |
+
enemy_p=gr.Textbox()
|
367 |
+
sky_s=gr.Textbox()
|
368 |
+
star_s=gr.Textbox()
|
369 |
+
enemy_s=gr.Textbox()
|
370 |
|
371 |
get_high_score_btn=gr.Button()
|
372 |
def return_score(text):
|
|
|
375 |
return None
|
376 |
get_high_score_btn.click(get_high_score,None,score_html)
|
377 |
get_score.click(return_score,score,[score],_js=score_js)
|
378 |
+
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,sky_p,star_p,enemy_p,sky_s,star_s,enemy_s],message)
|
379 |
update_game.click(refresh_frame,None,html_game).then(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game).then(get_high_score,None,score_html)
|
380 |
+
|
381 |
+
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url,sky_p,sky_s])
|
382 |
+
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url,star_p,star_s])
|
383 |
+
btn_enemy.click(enemy_fn,prompt_enemy,[out_im_enemy,out_enemy_url,enemy_p,enemy_s])
|
384 |
app.load(predict,[text_input,url_params],[text_input,html_game], _js=get_window_url_params)
|
385 |
|
386 |
#app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game)
|