Update app.py
Browse files
app.py
CHANGED
|
@@ -146,9 +146,9 @@ def save_game(background_img,star_img,enemy_img,platform_img,dude_img):
|
|
| 146 |
pass
|
| 147 |
block = {'index': len(lod) + 1,
|
| 148 |
'timestamp': timestamp,
|
| 149 |
-
'background_url': f'https://huggingface.co/datasets/{user_repo}/
|
| 150 |
-
'star_url': f'https://huggingface.co/datasets/{user_repo}/
|
| 151 |
-
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/
|
| 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 |
}
|
|
@@ -173,11 +173,12 @@ def save_game(background_img,star_img,enemy_img,platform_img,dude_img):
|
|
| 173 |
pass
|
| 174 |
score_js="""
|
| 175 |
|
| 176 |
-
function(text_input) {
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
text_input = Object.fromEntries(elmnt);
|
| 180 |
-
return [text_input];
|
| 181 |
}
|
| 182 |
"""
|
| 183 |
|
|
@@ -207,10 +208,17 @@ with gr.Blocks() as app:
|
|
| 207 |
html_game = gr.HTML()
|
| 208 |
save_btn=gr.Button("Save")
|
| 209 |
get_score=gr.Button("Get Score")
|
| 210 |
-
|
| 211 |
-
|
|
|
|
| 212 |
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
get_score.click(return_score,text_input,text_input,_js=score_js)
|
| 215 |
save_btn.click(save_game,[out_im_sky,out_im_star,out_im_enemy,out_im_enemy,out_im_enemy],None)
|
| 216 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
|
|
|
| 146 |
pass
|
| 147 |
block = {'index': len(lod) + 1,
|
| 148 |
'timestamp': timestamp,
|
| 149 |
+
'background_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/background/{timename}-background_img.png',
|
| 150 |
+
'star_url': f'https://huggingface.co/datasets/{user_repo}/resolve/main/images/star/{timename}-star_img.png',
|
| 151 |
+
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/resolve/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 |
}
|
|
|
|
| 173 |
pass
|
| 174 |
score_js="""
|
| 175 |
|
| 176 |
+
function(text_input,url_params) {
|
| 177 |
+
console.log(text_input, url_params);
|
| 178 |
+
const iframe = document.getElementById("myIframe");
|
| 179 |
+
const elmnt = iframe.contentWindow.document.getElementsByTagName("H1")[0];
|
| 180 |
text_input = Object.fromEntries(elmnt);
|
| 181 |
+
return [text_input,url_params];
|
| 182 |
}
|
| 183 |
"""
|
| 184 |
|
|
|
|
| 208 |
html_game = gr.HTML()
|
| 209 |
save_btn=gr.Button("Save")
|
| 210 |
get_score=gr.Button("Get Score")
|
| 211 |
+
with gr.Row():
|
| 212 |
+
text_input=gr.Textbox()
|
| 213 |
+
url_params=gr.Textbox()
|
| 214 |
|
| 215 |
+
def return_score(text, url_params):
|
| 216 |
+
'''if url_params.get('url') ==check_acc:
|
| 217 |
+
out = gr.update(visible=True)
|
| 218 |
+
else:
|
| 219 |
+
out=gr.update(visible=False)
|
| 220 |
+
#out=gr.HTML.update("""<head><meta http-equiv="refresh" content="0;URL='https://huggingface.co/spaces"></head>""")'''
|
| 221 |
+
return ["" + text + "", url_params]
|
| 222 |
get_score.click(return_score,text_input,text_input,_js=score_js)
|
| 223 |
save_btn.click(save_game,[out_im_sky,out_im_star,out_im_enemy,out_im_enemy,out_im_enemy],None)
|
| 224 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|