Omnibus commited on
Commit
b8f5b82
1 Parent(s): ea73469

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -65,12 +65,12 @@ def sky_fn(inp):
65
  width, height = outp.size
66
  rat = width/height
67
  if width > height:
68
- outp = outp.resize((600*rat,600))
69
  elif width < height:
70
- outp = outp.resize((800,800*rat))
71
  else:
72
- outp = outp.resize((800,536))
73
- outp.save(f"{uid}_sky.png")
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}'
@@ -104,7 +104,7 @@ def enemy_fn(inp):
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):
108
  user_repo=save_data.split('datasets/',1)[1].split('/raw',1)[0]
109
  timestamp=str(datetime.datetime.now())
110
  timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
@@ -129,7 +129,7 @@ def save_game(name,score):
129
  print(timestamp)
130
  try:
131
  api.upload_file(
132
- path_or_fileobj=f"{uid}_sky.png",
133
  path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
134
  repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
135
  token=token_self,
@@ -140,7 +140,7 @@ def save_game(name,score):
140
  pass
141
  try:
142
  api.upload_file(
143
- path_or_fileobj=f"{uid}_star.png",
144
  path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
145
  repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
146
  token=token_self,
@@ -151,7 +151,7 @@ def save_game(name,score):
151
  pass
152
  try:
153
  api.upload_file(
154
- path_or_fileobj=f"{uid}_enemy.png",
155
  path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
156
  repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
157
  token=token_self,
@@ -288,7 +288,7 @@ with gr.Blocks() as app:
288
  def return_score(text):
289
  return text
290
  get_score.click(return_score,score,[score],_js=score_js)
291
- save_btn.click(return_score,score,[score],_js=score_js).then(save_game,[game_name,score],message)
292
  update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
293
  btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
294
  btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
 
65
  width, height = outp.size
66
  rat = width/height
67
  if width > height:
68
+ outrs = outp.resize((600*rat,600))
69
  elif width < height:
70
+ outrs = outp.resize((800,800*rat))
71
  else:
72
+ outrs = outp.resize((800,536))
73
+ outrs.save(f"{uid}_sky.png")
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}'
 
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]
109
  timestamp=str(datetime.datetime.now())
110
  timename=timestamp.replace(" ","--").replace(":","-").replace(".","-")
 
129
  print(timestamp)
130
  try:
131
  api.upload_file(
132
+ path_or_fileobj=background_im,
133
  path_in_repo=f"{save_data.split('main/',1)[1]}/images/background/{game}-background_img.png",
134
  repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
135
  token=token_self,
 
140
  pass
141
  try:
142
  api.upload_file(
143
+ path_or_fileobj=star_im,
144
  path_in_repo=f"{save_data.split('main/',1)[1]}/images/star/{game}-star_img.png",
145
  repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
146
  token=token_self,
 
151
  pass
152
  try:
153
  api.upload_file(
154
+ path_or_fileobj=enemy_im,
155
  path_in_repo=f"{save_data.split('main/',1)[1]}/images/enemy/{game}-enemy_img.png",
156
  repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
157
  token=token_self,
 
288
  def return_score(text):
289
  return text
290
  get_score.click(return_score,score,[score],_js=score_js)
291
+ 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)
292
  update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
293
  btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
294
  btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])