|
import gradio as gr |
|
import diff |
|
import os |
|
from PIL import Image |
|
import uuid |
|
import random |
|
|
|
proc1=diff |
|
proc2=diff |
|
bg1=gr.Interface.load("spaces/Omnibus/fast-bg-remove-mod") |
|
|
|
|
|
sky = "https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/sky.png" |
|
platform = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/platform.png' |
|
star = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/star.png' |
|
bomb = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/bomb.png' |
|
dude = 'https://huggingface.co/spaces/Omnibus/game-test/resolve/main/assets/dude.png' |
|
|
|
|
|
|
|
def game_fn(sky=sky,star=star,bomb=bomb,platform=platform,dude=dude): |
|
html_mod=f""" |
|
<div id="demo" style="height:600px"> |
|
<iframe |
|
id="myIframe" |
|
src="https://omnibus-game-test-static.static.hf.space/index.html?sky={sky}&platform={platform}&star={star}&bomb={bomb}&dude={dude}" |
|
frameborder="0" |
|
width="100%" |
|
height="100%" |
|
></iframe> |
|
</div>""" |
|
return html_mod |
|
|
|
def update_game(inp): |
|
|
|
return game_fn(sky=sky) |
|
|
|
def sky_fn(inp): |
|
rand = random.randint(1,200) |
|
for i in range(rand): |
|
inp+=" " |
|
|
|
|
|
uid=uuid.uuid4() |
|
output=proc1.send_it(inp,5,1) |
|
|
|
|
|
print(output) |
|
outp=Image.open(output[0]) |
|
width, height = outp.size |
|
rat = width/height |
|
if width > height: |
|
outp = outp.resize((600*rat,600)) |
|
elif width < height: |
|
outp = outp.resize((800,800*rat)) |
|
else: |
|
outp = outp.resize((800,536)) |
|
outp.save(f"{uid}_sky.png") |
|
out = os.path.abspath(f"{uid}_sky.png") |
|
|
|
out_url = f'https://omnibus-game-test.hf.space/file={out}' |
|
return output[0],out_url |
|
|
|
def star_fn(inp): |
|
rand = random.randint(1,200) |
|
for i in range(rand): |
|
inp+=" " |
|
|
|
|
|
uid=uuid.uuid4() |
|
|
|
output=proc2.send_it(inp,5,1) |
|
print(output) |
|
|
|
|
|
|
|
outp=Image.open(output[0]) |
|
outp.save(f"{uid}_pre_star.png") |
|
|
|
out = os.path.abspath(f"{uid}_pre_star.png") |
|
out_pre_url = f'https://omnibus-game-test.hf.space/file={out}' |
|
|
|
|
|
outp_bg=bg1(out_pre_url) |
|
|
|
bg_im=Image.open(outp_bg) |
|
print(f'outp_bg:: {outp_bg}') |
|
outp = bg_im.resize((24,24)) |
|
outp.save(f"{uid}_star.png") |
|
out = os.path.abspath(f"{uid}_star.png") |
|
out_url = f'https://omnibus-game-test.hf.space/file={out}' |
|
return out_url,out_url |
|
|
|
with gr.Blocks() as app: |
|
with gr.Row(): |
|
with gr.Column(): |
|
with gr.Row(): |
|
prompt_sky=gr.Textbox(label="Background",value="beautiful landscape, real, 8k") |
|
btn_sky=gr.Button("Make") |
|
with gr.Row(): |
|
prompt_star=gr.Textbox(label="Star",value="Star") |
|
btn_star=gr.Button("Make") |
|
with gr.Row(): |
|
update_game=gr.Button("Use Image") |
|
out_im_sky=gr.Image(type='filepath',width=50) |
|
out_im_star=gr.Image(type='filepath',width=50) |
|
out_sky_url=gr.Textbox(visible=False) |
|
out_star_url=gr.Textbox(visible=False) |
|
|
|
html_game = gr.HTML() |
|
|
|
update_game.click(game_fn,[out_sky_url,out_star_url],html_game) |
|
btn_sky.click(sky_fn,prompt_sky,[out_im_sky,out_sky_url]) |
|
btn_star.click(star_fn,prompt_star,[out_im_star,out_star_url]) |
|
app.load(sky_fn,prompt_sky,[out_im_sky,out_sky_url]).then(game_fn,[out_sky_url],html_game) |
|
app.queue(concurrency_count=10).launch() |