Update app.py
Browse files
app.py
CHANGED
@@ -74,7 +74,7 @@ def sky_fn(inp):
|
|
74 |
out = os.path.abspath(f"{uid}_sky.png")
|
75 |
#out = os.path.abspath(outp)
|
76 |
out_url = f'https://omnibus-game-test.hf.space/file={out}'
|
77 |
-
return outp,out_url
|
78 |
|
79 |
def star_fn(inp):
|
80 |
rand = random.randint(1,200)
|
@@ -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 out,out_url
|
92 |
|
93 |
def enemy_fn(inp):
|
94 |
rand = random.randint(1,200)
|
@@ -102,7 +102,7 @@ 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 out,out_url
|
106 |
|
107 |
def save_game(name,score,background_im,star_im,enemy_im):
|
108 |
user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
|
@@ -132,7 +132,7 @@ def save_game(name,score,background_im,star_im,enemy_im):
|
|
132 |
t1.write(i1)
|
133 |
try:
|
134 |
api.upload_file(
|
135 |
-
path_or_fileobj=
|
136 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
|
137 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
138 |
token=token_self,
|
@@ -148,7 +148,7 @@ def save_game(name,score,background_im,star_im,enemy_im):
|
|
148 |
t2.write(i2)
|
149 |
try:
|
150 |
api.upload_file(
|
151 |
-
path_or_fileobj=
|
152 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
|
153 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
154 |
token=token_self,
|
@@ -164,7 +164,7 @@ def save_game(name,score,background_im,star_im,enemy_im):
|
|
164 |
t3.write(i3)
|
165 |
try:
|
166 |
api.upload_file(
|
167 |
-
path_or_fileobj=
|
168 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
|
169 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
170 |
token=token_self,
|
@@ -301,14 +301,19 @@ with gr.Blocks() as app:
|
|
301 |
text_input=gr.Textbox()
|
302 |
url_params = gr.JSON({}, visible=True, label="")
|
303 |
acc=gr.Textbox()
|
|
|
|
|
|
|
|
|
|
|
304 |
def return_score(text):
|
305 |
return text
|
306 |
get_score.click(return_score,score,[score],_js=score_js)
|
307 |
-
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score,
|
308 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
309 |
-
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
310 |
-
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|
311 |
-
btn_enemy.click(enemy_fn,prompt_enemy,[out_im_enemy,out_enemy_url])
|
312 |
app.load(predict,[text_input,url_params],[text_input,html_game], _js=get_window_url_params)
|
313 |
|
314 |
#app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game)
|
|
|
74 |
out = os.path.abspath(f"{uid}_sky.png")
|
75 |
#out = os.path.abspath(outp)
|
76 |
out_url = f'https://omnibus-game-test.hf.space/file={out}'
|
77 |
+
return outp,out_url,outrs
|
78 |
|
79 |
def star_fn(inp):
|
80 |
rand = random.randint(1,200)
|
|
|
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,outrs
|
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,outrs
|
106 |
|
107 |
def save_game(name,score,background_im,star_im,enemy_im):
|
108 |
user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
|
|
|
132 |
t1.write(i1)
|
133 |
try:
|
134 |
api.upload_file(
|
135 |
+
path_or_fileobj=background_im,
|
136 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
|
137 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
138 |
token=token_self,
|
|
|
148 |
t2.write(i2)
|
149 |
try:
|
150 |
api.upload_file(
|
151 |
+
path_or_fileobj=star_im,
|
152 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
|
153 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
154 |
token=token_self,
|
|
|
164 |
t3.write(i3)
|
165 |
try:
|
166 |
api.upload_file(
|
167 |
+
path_or_fileobj=enemy_im,
|
168 |
path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
|
169 |
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
170 |
token=token_self,
|
|
|
301 |
text_input=gr.Textbox()
|
302 |
url_params = gr.JSON({}, visible=True, label="")
|
303 |
acc=gr.Textbox()
|
304 |
+
with gr.Row():
|
305 |
+
hid_sky=gr.Image(type='filepath')
|
306 |
+
hid_star=gr.Image(type='filepath')
|
307 |
+
hid_enemy=gr.Image(type='filepath')
|
308 |
+
|
309 |
def return_score(text):
|
310 |
return text
|
311 |
get_score.click(return_score,score,[score],_js=score_js)
|
312 |
+
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score,hid_sky,hid_star,hid_enemy],message)
|
313 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
314 |
+
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url,hid_sky])
|
315 |
+
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url,hid_star])
|
316 |
+
btn_enemy.click(enemy_fn,prompt_enemy,[out_im_enemy,out_enemy_url,hid_enemy])
|
317 |
app.load(predict,[text_input,url_params],[text_input,html_game], _js=get_window_url_params)
|
318 |
|
319 |
#app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game)
|