Omnibus commited on
Commit
6d47bd1
1 Parent(s): caa7b09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -23,7 +23,7 @@ dude = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/dude
23
 
24
  def game_fn(sky=sky,star=star,bomb=bomb,platform=platform,dude=dude):
25
  html_mod=f"""
26
- <div id="demo" style="height:600px">
27
  <iframe
28
  id="myIframe"
29
  src="https://omnibus-game-test-static.static.hf.space/index.html?sky={sky}&platform={platform}&star={star}&bomb={bomb}&dude={dude}"
@@ -66,19 +66,26 @@ def star_fn(inp):
66
  inp+=" "
67
  uid=uuid.uuid4()
68
  output=proc2.send_it(inp,5,1)
69
- print(output)
70
  outp=Image.open(output[0])
71
- #outp.save(f"{uid}_star.png")
72
- print("removing background")
73
  out=rm(outp)
74
- print("resizing")
75
- #outrs = out.resize((24,24))
76
  outrs = out.resize((36,36))
77
-
78
  outrs.save(f"{uid}_star.png")
79
  out_file = os.path.abspath(f"{uid}_star.png")
80
  out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
81
-
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  return out,out_url
83
 
84
  with gr.Blocks() as app:
@@ -93,17 +100,23 @@ with gr.Blocks() as app:
93
  btn_star=gr.Button("Make")
94
  out_im_star=gr.Image(type='filepath')
95
  out_star_url=gr.Textbox(visible=False)
96
- gr.Column()
 
 
 
 
97
  gr.Column()
98
  gr.Column()
99
 
100
  with gr.Row():
101
- update_game=gr.Button("Use Image")
102
  #start_prompt=gr.Textbox(value="beautiful landscape, real, 8k",visible=False)
103
  html_game = gr.HTML()
104
 
105
- update_game.click(game_fn,[out_sky_url,out_star_url],html_game)
106
  btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url])
107
  btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url])
 
 
108
  #app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game)
109
  app.queue(concurrency_count=10).launch(show_api=False)
 
23
 
24
  def game_fn(sky=sky,star=star,bomb=bomb,platform=platform,dude=dude):
25
  html_mod=f"""
26
+ <div id="my_game" style="height:600px">
27
  <iframe
28
  id="myIframe"
29
  src="https://omnibus-game-test-static.static.hf.space/index.html?sky={sky}&platform={platform}&star={star}&bomb={bomb}&dude={dude}"
 
66
  inp+=" "
67
  uid=uuid.uuid4()
68
  output=proc2.send_it(inp,5,1)
 
69
  outp=Image.open(output[0])
 
 
70
  out=rm(outp)
 
 
71
  outrs = out.resize((36,36))
 
72
  outrs.save(f"{uid}_star.png")
73
  out_file = os.path.abspath(f"{uid}_star.png")
74
  out_url = f'https://omnibus-game-test.hf.space/file={out_file}'
75
+ return out,out_url
76
+
77
+ def enemy_fn(inp):
78
+ rand = random.randint(1,200)
79
+ for i in range(rand):
80
+ inp+=" "
81
+ uid=uuid.uuid4()
82
+ output=proc2.send_it(inp,5,1)
83
+ outp=Image.open(output[0])
84
+ out=rm(outp)
85
+ outrs = out.resize((24,24))
86
+ outrs.save(f"{uid}_enemy.png")
87
+ out_file = os.path.abspath(f"{uid}_enemy.png")
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:
 
100
  btn_star=gr.Button("Make")
101
  out_im_star=gr.Image(type='filepath')
102
  out_star_url=gr.Textbox(visible=False)
103
+ with gr.Column():
104
+ prompt_enemy=gr.Textbox(label="Enemy",value="Ball on fire, blank background")
105
+ btn_enemy=gr.Button("Make")
106
+ out_im_enemy=gr.Image(type='filepath')
107
+ out_enemy_url=gr.Textbox(visible=False)
108
  gr.Column()
109
  gr.Column()
110
 
111
  with gr.Row():
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])
119
+ btn_enemy.click(enemy_fn,prompt_enemy,[out_im_enemy,out_enemy_url])
120
+
121
  #app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game)
122
  app.queue(concurrency_count=10).launch(show_api=False)