Spaces:
Paused
Paused
File size: 3,410 Bytes
93647e8 5e8a161 26359f2 b3b34ea 0d644e2 7d10f1c 0b317b0 a91f570 ac365e7 43efaa8 ac365e7 0b317b0 7d10f1c 634ecf0 26359f2 93647e8 634ecf0 60bf902 7d10f1c 43de632 93647e8 2c18ec2 26359f2 c33913d 26359f2 b3b34ea 943e0df 01849e6 7d10f1c 0a0db87 a91f570 b7a9a49 b3b34ea a91f570 56e0f5a a91f570 0a0db87 a91f570 7d10f1c a91f570 0a0db87 a91f570 7d10f1c a91f570 7d10f1c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import gradio as gr
import os
from gradio_client import Client
title="Prompt Converter"
description="""
<h1>Prompt Converter</h1>
<p style="text-align:center;">
Stable Diffusion 2 uses OpenCLIP ViT-H model trained on LAION dataset so it knows different things than the OpenAI ViT-L we're all used to prompting.
<br />This demo converts a v1.x stable diffusion prompt to a stable diffusion 2.x prompt,
<br />by generating an image through <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" target="_blank">RunwayML Stable Diffusion 1.5</a>, then Interrogate the resulting image through <a href="https://huggingface.co/spaces/fffiloni/CLIP-Interrogator-2" target="_blank">CLIP Interrogator 2</a> to give you a Stable Diffusion 2 equivalent prompt.
</p>
"""
stable_diffusion = Client("https://runwayml-stable-diffusion-v1-5.hf.space/")
clip_interrogator_2 = Client("https://fffiloni-clip-interrogator-2.hf.space/")
def get_images(prompt):
print("Calling SD")
gallery_dir = stable_diffusion.predict(prompt, fn_index=2)
print(f"Gallery Directory: {gallery_dir}")
img_results = [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
return img_results[0]
def get_new_prompt(img, mode):
interrogate = clip_interrogator_2.predict(
img, # str (filepath or URL to image) in 'parameter_3' Image component
mode, # str in 'Select mode' Radio component
12, # int | float (numeric value between 2 and 24) in 'best mode max flavors' Slider component
api_name="/clipi2"
)
#interrogate = clip_interrogator_2(img, mode, 12, api_name="clipi2")
return interrogate
def infer(prompt, mode):
img = get_images(prompt)
result = get_new_prompt(img, mode)
#return result[0], img
return img
with gr.Blocks() as demo:
gr.HTML(description)
with gr.Row():
with gr.Column():
prompt_input = gr.Textbox(lines=4, label="Input v1.x Stable Diffusion prompt")
mode_input = gr.Radio(['best', 'classic', 'fast'], label='mode', value='fast')
submit_btn = gr.Button("Submit")
with gr.Column():
sd_inter = gr.Image()
prompt_output = gr.Textbox(lines=4, label="Converted v2.x Stable Diffusion prompt")
submit_btn.click(
fn=infer, inputs=[prompt_input,mode_input], outputs=[sd_inter]
)
examples=[
["girl with steampunk weapons and uniform, serious, finely detailed, made by wlop, boichi, ilya kuvshinov, full body portrait, illustration, grass, sunny, sky, anime, side view, perfect anime face, detailed face, zoomed out, smooth","fast"],
["a yellow cockatiel riding on the rings of saturn wearing a propeller hat, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, art by artgerm and greg rutkowski and alphonse mucha ","classic"],
["painting, view from inside edward hopper's painting nighthawks, of a group of werebears robbing a bank, foggy ","best"]
]
gr.Examples(
examples = examples,
fn = infer,
inputs=[prompt_input,mode_input],
outputs=[sd_inter]
)
#demo=gr.Interface(fn=infer, inputs=[prompt_input,mode_input], outputs=[prompt_output],title=title,description=description,examples=examples)
demo.queue(max_size=10,concurrency_count=20)
demo.launch(enable_queue=True) |