Update app.py
Browse files
app.py
CHANGED
|
@@ -1,75 +1,28 @@
|
|
| 1 |
# ==============================
|
| 2 |
-
#
|
| 3 |
-
# ==============================
|
| 4 |
-
|
| 5 |
-
#import gradio as gr
|
| 6 |
-
#demo = gr.load("mswhite/miamivice", src="models")
|
| 7 |
-
#demo.launch()
|
| 8 |
-
|
| 9 |
-
# ==============================
|
| 10 |
-
# Detailed Interface
|
| 11 |
# ==============================
|
| 12 |
|
|
|
|
| 13 |
import os
|
| 14 |
import gradio as gr
|
| 15 |
import torch
|
| 16 |
from diffusers import DiffusionPipeline, StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 17 |
|
| 18 |
-
# Nvidia GPU config
|
| 19 |
-
|
| 20 |
-
#from diffusers import DiffusionPipeline
|
| 21 |
-
#pipe = DiffusionPipeline.from_pretrained("mswhite/nnn-model")
|
| 22 |
-
|
| 23 |
pipe = StableDiffusionPipeline.from_pretrained("mswhite/bricksburg_model", torch_dtype=torch.float16) #, safety_checker=None)
|
| 24 |
pipe = pipe.to("cuda")
|
| 25 |
pipe.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
# Optional Img2Img pipeline
|
| 31 |
-
|
| 32 |
-
#pipe_img = StableDiffusionImg2ImgPipeline.from_pretrained("mswhite/miamivice", torch_dtype=torch.float16, safety_checker=None)
|
| 33 |
-
#pipe_img = pipe_img.to("cuda")
|
| 34 |
-
|
| 35 |
-
# Sample Prompt - "bright clean clear illustration side profile of a woman wearing pink lipstick p_nagel"
|
| 36 |
-
|
| 37 |
-
def nagelize(text):
|
| 38 |
prompt = "mini_mw_lgo" + text
|
| 39 |
return pipe(prompt).images[0]
|
| 40 |
|
| 41 |
-
#def nagelize_me(source_image):
|
| 42 |
-
# prompt = "p_nagel"
|
| 43 |
-
# return pipe_img(prompt, image=source_image, strength=0.6, num_inference_steps=500, guidance_scale=40.0).images[0]
|
| 44 |
-
|
| 45 |
-
# Web Version of Blocks()
|
| 46 |
-
|
| 47 |
-
#with gr.Blocks() as demo:
|
| 48 |
-
|
| 49 |
-
#girl_image = gr.Image(label = None, value = os.path.join(os.path.dirname(__file__), "headshot.jpg"), visible=False)
|
| 50 |
-
|
| 51 |
-
# with gr.Row():
|
| 52 |
-
# logo_image = gr.Image(label = None, value = os.path.join(os.path.dirname(__file__), "miami.jpg"), interactive=True).style(height=720)
|
| 53 |
-
# #gr.Markdown("<img src=https://huggingface.co/spaces/mswhite/miamivice/resolve/main/miami.jpg width=720px>")
|
| 54 |
-
# output = gr.Image(label="Output").style(height=720)
|
| 55 |
-
# with gr.Row():
|
| 56 |
-
# art_to_draw = gr.Textbox(label="Prompt to Draw: e.g. woman with red hair")
|
| 57 |
-
# flashb_btn = gr.Button("Flashback to the 80s")
|
| 58 |
-
# #back80_btn = gr.Button("Send me back to the 80s")
|
| 59 |
-
|
| 60 |
-
# flashb_btn.click(fn=nagelize, inputs=[art_to_draw], outputs=[output])
|
| 61 |
-
# #back80_btn.click(fn=nagelize, inputs=[art_to_draw], outputs=[output])
|
| 62 |
-
|
| 63 |
-
# Mobile Version of Blocks
|
| 64 |
-
|
| 65 |
with gr.Blocks() as demo:
|
| 66 |
|
| 67 |
gr.Markdown("<img src=https://huggingface.co/spaces/mswhite/Bricksburg/resolve/main/Emmet.jpg width=720px>")
|
| 68 |
output = gr.Image(label="Output").style(width=720)
|
| 69 |
art_to_draw = gr.Textbox(label="Prompt to Draw: e.g. ")
|
| 70 |
flashb_btn = gr.Button("Everything is Awesome in Bricksburg")
|
| 71 |
-
flashb_btn.click(fn=
|
| 72 |
|
| 73 |
demo.launch()
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 1 |
# ==============================
|
| 2 |
+
# Program
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
# ==============================
|
| 4 |
|
| 5 |
+
import spaces
|
| 6 |
import os
|
| 7 |
import gradio as gr
|
| 8 |
import torch
|
| 9 |
from diffusers import DiffusionPipeline, StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
pipe = StableDiffusionPipeline.from_pretrained("mswhite/bricksburg_model", torch_dtype=torch.float16) #, safety_checker=None)
|
| 12 |
pipe = pipe.to("cuda")
|
| 13 |
pipe.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
| 14 |
|
| 15 |
+
@spaces.GPU
|
| 16 |
+
def legoize(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
prompt = "mini_mw_lgo" + text
|
| 18 |
return pipe(prompt).images[0]
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
|
| 22 |
gr.Markdown("<img src=https://huggingface.co/spaces/mswhite/Bricksburg/resolve/main/Emmet.jpg width=720px>")
|
| 23 |
output = gr.Image(label="Output").style(width=720)
|
| 24 |
art_to_draw = gr.Textbox(label="Prompt to Draw: e.g. ")
|
| 25 |
flashb_btn = gr.Button("Everything is Awesome in Bricksburg")
|
| 26 |
+
flashb_btn.click(fn=legoize, inputs=[art_to_draw], outputs=[output])
|
| 27 |
|
| 28 |
demo.launch()
|
|
|
|
|
|