Update app.py
Browse files
app.py
CHANGED
@@ -18,8 +18,6 @@ this_url='https://omnibus-game-test.hf.space/'
|
|
18 |
save_data='https://huggingface.co/datasets/Omnibus/game-data-1/raw/main/'
|
19 |
token_self = os.environ['HF_TOKEN']
|
20 |
api=HfApi(token=token_self)
|
21 |
-
#bg1=gr.Interface.load("spaces/Omnibus/fast-bg-remove-mod")
|
22 |
-
#proc2=gr.Interface.load("spaces/Omnibus/fast-diff")
|
23 |
|
24 |
sky = "https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/sky.png"
|
25 |
platform = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/platform.png'
|
@@ -35,8 +33,6 @@ get_window_url_params = """
|
|
35 |
return [text_input, url_params];
|
36 |
}
|
37 |
"""
|
38 |
-
|
39 |
-
|
40 |
def game_fn(sky=sky,star=star,bomb=bomb,platform=platform,dude=dude):
|
41 |
html_mod=f"""
|
42 |
<div id="my_game" style="height:600px;width:100%">
|
@@ -51,7 +47,6 @@ def game_fn(sky=sky,star=star,bomb=bomb,platform=platform,dude=dude):
|
|
51 |
return html_mod
|
52 |
|
53 |
def update_game(inp):
|
54 |
-
|
55 |
return game_fn(sky=sky)
|
56 |
|
57 |
def sky_fn(inp):
|
@@ -240,7 +235,26 @@ def predict(text, url_params):
|
|
240 |
else:
|
241 |
pass
|
242 |
return ["" + text + "", ""]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
|
|
|
|
|
|
|
|
244 |
score_js="""
|
245 |
|
246 |
function(text_input) {
|
@@ -274,7 +288,12 @@ with gr.Blocks() as app:
|
|
274 |
with gr.Row():
|
275 |
update_game=gr.Button("Make Game")
|
276 |
#start_prompt=gr.Textbox(value="beautiful landscape, real, 8k",visible=False)
|
277 |
-
|
|
|
|
|
|
|
|
|
|
|
278 |
with gr.Row():
|
279 |
game_name=gr.Textbox(label="Name for Game (optional)")
|
280 |
save_btn=gr.Button("Save")
|
@@ -287,10 +306,12 @@ with gr.Blocks() as app:
|
|
287 |
text_input=gr.Textbox()
|
288 |
url_params = gr.JSON({}, visible=True, label="")
|
289 |
acc=gr.Textbox()
|
290 |
-
|
291 |
-
|
292 |
def return_score(text):
|
293 |
return text
|
|
|
|
|
294 |
get_score.click(return_score,score,[score],_js=score_js)
|
295 |
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score],message)
|
296 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
|
|
18 |
save_data='https://huggingface.co/datasets/Omnibus/game-data-1/raw/main/'
|
19 |
token_self = os.environ['HF_TOKEN']
|
20 |
api=HfApi(token=token_self)
|
|
|
|
|
21 |
|
22 |
sky = "https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/sky.png"
|
23 |
platform = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/platform.png'
|
|
|
33 |
return [text_input, url_params];
|
34 |
}
|
35 |
"""
|
|
|
|
|
36 |
def game_fn(sky=sky,star=star,bomb=bomb,platform=platform,dude=dude):
|
37 |
html_mod=f"""
|
38 |
<div id="my_game" style="height:600px;width:100%">
|
|
|
47 |
return html_mod
|
48 |
|
49 |
def update_game(inp):
|
|
|
50 |
return game_fn(sky=sky)
|
51 |
|
52 |
def sky_fn(inp):
|
|
|
235 |
else:
|
236 |
pass
|
237 |
return ["" + text + "", ""]
|
238 |
+
|
239 |
+
def get_high_score():
|
240 |
+
try:
|
241 |
+
r = requests.get(f'{save_data}game_data.json')
|
242 |
+
lod = json.loads(r.text)
|
243 |
+
high_score=[]
|
244 |
+
high_score.append
|
245 |
+
#lod.sort()
|
246 |
+
for ea in lod:
|
247 |
+
print (ea)
|
248 |
+
print (ea[0]['game_name'])
|
249 |
+
print (ea[0]['score'])
|
250 |
+
high_score.append(f"{ea[0]['game_name']}\n{ea[0]['score']}")
|
251 |
+
#high_score.sort()
|
252 |
+
return high_score
|
253 |
|
254 |
+
except Exception as e:
|
255 |
+
return e
|
256 |
+
|
257 |
+
|
258 |
score_js="""
|
259 |
|
260 |
function(text_input) {
|
|
|
288 |
with gr.Row():
|
289 |
update_game=gr.Button("Make Game")
|
290 |
#start_prompt=gr.Textbox(value="beautiful landscape, real, 8k",visible=False)
|
291 |
+
|
292 |
+
with gr.Row():
|
293 |
+
with gr.Column(scale=3):
|
294 |
+
html_game = gr.HTML()
|
295 |
+
with gr.Column(scale=1):
|
296 |
+
score_html =gr.HTML()
|
297 |
with gr.Row():
|
298 |
game_name=gr.Textbox(label="Name for Game (optional)")
|
299 |
save_btn=gr.Button("Save")
|
|
|
306 |
text_input=gr.Textbox()
|
307 |
url_params = gr.JSON({}, visible=True, label="")
|
308 |
acc=gr.Textbox()
|
309 |
+
|
310 |
+
get_high_score_btn=gr.Button()
|
311 |
def return_score(text):
|
312 |
return text
|
313 |
+
|
314 |
+
get_high_score_btn.click(get_high_score,None,score_html)
|
315 |
get_score.click(return_score,score,[score],_js=score_js)
|
316 |
save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score],message)
|
317 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|