Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,12 @@ import uuid
|
|
| 6 |
import random
|
| 7 |
import bg
|
| 8 |
from rembg import remove as rm
|
|
|
|
| 9 |
proc1=diff
|
| 10 |
proc2=diff
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
#bg1=gr.Interface.load("spaces/Omnibus/fast-bg-remove-mod")
|
| 14 |
#proc2=gr.Interface.load("spaces/Omnibus/fast-diff")
|
|
@@ -88,6 +91,64 @@ def enemy_fn(inp):
|
|
| 88 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
| 89 |
return out,out_url
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
with gr.Blocks() as app:
|
| 92 |
with gr.Row():
|
| 93 |
with gr.Column():
|
|
@@ -112,7 +173,9 @@ with gr.Blocks() as app:
|
|
| 112 |
update_game=gr.Button("Make Game")
|
| 113 |
#start_prompt=gr.Textbox(value="beautiful landscape, real, 8k",visible=False)
|
| 114 |
html_game = gr.HTML()
|
| 115 |
-
|
|
|
|
|
|
|
| 116 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
| 117 |
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
| 118 |
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|
|
|
|
| 6 |
import random
|
| 7 |
import bg
|
| 8 |
from rembg import remove as rm
|
| 9 |
+
import datatime
|
| 10 |
proc1=diff
|
| 11 |
proc2=diff
|
| 12 |
|
| 13 |
+
save_data='https://huggingface.co/datasets/Omnibus/game-data-1/raw/main/'
|
| 14 |
+
token_self = os.environ['HF_TOKEN']
|
| 15 |
|
| 16 |
#bg1=gr.Interface.load("spaces/Omnibus/fast-bg-remove-mod")
|
| 17 |
#proc2=gr.Interface.load("spaces/Omnibus/fast-diff")
|
|
|
|
| 91 |
out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
|
| 92 |
return out,out_url
|
| 93 |
|
| 94 |
+
def save_game(background_img,star_img,enemy_img,platform_img,dude_img):
|
| 95 |
+
#background_image.save(f"{uid}-background_img.png")
|
| 96 |
+
#star_img.save(f"{uid}-star_img.png")
|
| 97 |
+
#enemy_img.save(f"{uid}-enemy_img.png")
|
| 98 |
+
#platform_img.save(f"{uid}-platform_img.png")
|
| 99 |
+
#dude_img.save(f"{uid}-dude_img.png")
|
| 100 |
+
|
| 101 |
+
user_repo=game_data.split('datasets/',1)[1].split('/raw',1)[0]
|
| 102 |
+
try:
|
| 103 |
+
r = requests.get(f'{save_data}/game_data.json')
|
| 104 |
+
lod = json.loads(r.text)
|
| 105 |
+
except:
|
| 106 |
+
lod=[]
|
| 107 |
+
pass
|
| 108 |
+
timestamp=str(datetime.datetime.now())
|
| 109 |
+
print(timestamp)
|
| 110 |
+
try:
|
| 111 |
+
api.upload_file(
|
| 112 |
+
path_or_fileobj=background_img,
|
| 113 |
+
path_in_repo=f"{game_data.split('main/',1)[1]}/images/background/{uid}-background_img.png",
|
| 114 |
+
repo_id=game_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 115 |
+
token=token_self,
|
| 116 |
+
repo_type="dataset",
|
| 117 |
+
)
|
| 118 |
+
#os.remove("tmp1.json")
|
| 119 |
+
|
| 120 |
+
except Exception as e:
|
| 121 |
+
print (e)
|
| 122 |
+
pass
|
| 123 |
+
block = {'index': len(lod) + 1,
|
| 124 |
+
'timestamp': timestamp,
|
| 125 |
+
'background_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/background/{uid}-background_img.png',
|
| 126 |
+
'star_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/star/{star_img}',
|
| 127 |
+
'enemy_url': f'https://huggingface.co/datasets/{user_repo}/raw/main/images/enemy/{enemy_img}',
|
| 128 |
+
#'platform_url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{platform_img}',
|
| 129 |
+
#'dude_url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{dude_img}',
|
| 130 |
+
}
|
| 131 |
+
print(block)
|
| 132 |
+
lod.append(block)
|
| 133 |
+
|
| 134 |
+
json_object = json.dumps(lod, indent=4)
|
| 135 |
+
with open("tmp1.json", "w") as outfile:
|
| 136 |
+
outfile.write(json_object)
|
| 137 |
+
try:
|
| 138 |
+
api.upload_file(
|
| 139 |
+
path_or_fileobj="tmp1.json",
|
| 140 |
+
path_in_repo=f"{save_data.split('main/',1)[1]}/game_data.json",
|
| 141 |
+
repo_id=save_data.split('datasets/',1)[1].split('/raw',1)[0],
|
| 142 |
+
token=token_self,
|
| 143 |
+
repo_type="dataset",
|
| 144 |
+
)
|
| 145 |
+
os.remove("tmp1.json")
|
| 146 |
+
print("success")
|
| 147 |
+
except Exception as e:
|
| 148 |
+
print (e)
|
| 149 |
+
pass
|
| 150 |
+
|
| 151 |
+
|
| 152 |
with gr.Blocks() as app:
|
| 153 |
with gr.Row():
|
| 154 |
with gr.Column():
|
|
|
|
| 173 |
update_game=gr.Button("Make Game")
|
| 174 |
#start_prompt=gr.Textbox(value="beautiful landscape, real, 8k",visible=False)
|
| 175 |
html_game = gr.HTML()
|
| 176 |
+
save_btn=gr.Button("Save (Experimental)")
|
| 177 |
+
|
| 178 |
+
save_btn.click(save_game,[out_im_sky,out_im_star,out_im_enemy,out_im_enemy,out_im_enemy],None)
|
| 179 |
update_game.click(game_fn,[out_sky_url,out_star_url,out_enemy_url],html_game)
|
| 180 |
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
|
| 181 |
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
|