import gradio as gr import diff import os from PIL import Image import uuid dif = gr.Interface.load("models/stabilityai/stable-diffusion-2-1-base", live=True), 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,platform=platform,star=star,bomb=bomb,dude=dude): html_mod=f"""
""" return html_mod def update_game(): return game_fn(sky=sky) def dif_fn(inp): uid=uuid.uuid4() #output=diff.send_it(inp,5,1) output=dif(inp) outp=Image.open(output) 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 with gr.Blocks() as app: with gr.Row(): with gr.Column(): prompt=gr.Textbox() with gr.Row(): btn=gr.Button("Make Image") update_game=gr.Button("Use Image") out_im=gr.Image(type='filepath') out_url=gr.Textbox(visible=False) start_prompt=gr.Textbox(value="A beautiful landscape",visible=False) html_game = gr.HTML() update_game.click(game_fn,[out_url],html_game) btn.click(dif_fn,prompt,[out_im,out_url]) app.load(dif_fn,start_prompt,[out_im,out_url]).then(game_fn,[out_url],html_game) app.launch()