Spaces:
Running
Running
File size: 5,019 Bytes
0af2966 0a5afa4 814f2f7 06a6567 9b1e068 d4f61d6 06a6567 ea12c1c fab5a52 3013b8f e8d6c5d ea12c1c 0af2966 ea12c1c 0af2966 ea12c1c 0af2966 74d93be 41eacca ea12c1c 41eacca ea12c1c 21ee151 d4a6fd0 6d903a0 85909a2 21ee151 c966517 ac2f2f8 0af2966 74d93be 1750151 ac2f2f8 9e8c67b f328f26 ac2f2f8 a928ddc 74d93be 93f37d2 e56cbf6 93f37d2 74d93be be017c6 93f37d2 85909a2 93f37d2 74d93be 5e35be2 9b6295a |
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 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import gradio as gr
from huggingface_hub import InferenceClient
import threading
import os
API_TOKEN = os.environ.get("API_TOKEN")
DEFAULT_NEGATIVE_INPUT = "nsfw, nude, nudity, naked, pantsless, boob, boobs, extra fingers, fewer fingers, (worst quality:1.4), (low quality:1.4), (monochrome:1.1), (bad_prompt_version2:0.8), text, jpeg, watermark, artist sign, blurry, out of frame, multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3), (mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, lowres, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, fused feet, bad feet, poorly drawn feet, extra feet, melting feet, fused feet, liquid feet, missing toes, bad toes, fused toes, poorly drawn toes, extra toes, fused eyes, missing eyes, liquid eyes, blurry eyes, fused lips, missing mouth, liquid mouth, expressionless, no expression, null face, liquid face, swirly face, no error correction,"
API_ENDPOINTS = {
"Kawaii": "Ojimi/anime-kawai-diffusion",
"Realistic": "Yntec/InsaneRealisticCVAE",
"Pixel": "nerijs/pixel-art-xl",
"Cartoon": "Yntec/sexyToons",
"Sprite": "Onodofthenorth/SD_PixelArt_SpriteSheet_Generator",
"Aesthetic": "playgroundai/playground-v2-1024px-aesthetic",
"AestheticL": "playgroundai/playground-v2-512px-base",
"OpenDalle": "dataautogpt3/OpenDalleV1.1",
"Default": "gsdf/Counterfeit-V2.5",
}
CHOICES = []
CLIENTS = {}
for model_name, model_endpoint in API_ENDPOINTS.items():
CHOICES.append(model_name)
CLIENTS[model_name] = InferenceClient(model_endpoint, headers = { "Authorization": f"Bearer {API_TOKEN}" })
def generate(inputs, model, anti_inputs = DEFAULT_NEGATIVE_INPUT, ht = 512, wt = 512, nis = 50, gs = 7.5, seed = 42):
print("MODEL CALLED: Input: " + inputs + ", Model: " + str(model))
output = CLIENTS[model].text_to_image(
inputs,
negative_prompt = anti_inputs,
height = int(ht),
width = int(wt),
num_inference_steps = int(nis),
guidance_scale = float(gs),
seed = int(seed)
)
return (output)
def cloud():
print("[CLOUD] | Reloading all existing models...")
for model_name, model_client in CLIENTS.items():
try:
threading.Thread(target=CLIENTS[model_name].text_to_image, args=("Preload",), kwargs={
"negative_prompt": "",
"height": int(512),
"width": int(512),
"num_inference_steps": int(1),
"guidance_scale": float(1),
"seed": int(0)
}).start()
except Exception as e:
print(f"[PRELOAD ERROR] An error occurred: {e}")
print("[CLOUD] | Reload successful.")
with gr.Blocks() as demo:
with gr.Row(variant = "panel"):
gr.Markdown("✨ A IDM space owned within Statical.")
with gr.Row():
with gr.Column():
model = gr.Dropdown(choices = CHOICES, value = next(iter(API_ENDPOINTS)), interactive = True, label = "Model")
with gr.Row():
with gr.Column():
prompt_text = gr.Textbox(label = "Your Prompt", lines = 4)
negative_prompt_text = gr.Textbox(label = "Your Negative Prompt", lines = 4, value = DEFAULT_NEGATIVE_INPUT)
run = gr.Button("Generate Image")
maintain = gr.Button("☁☁️")
height = gr.Slider( minimum = 144, maximum = 2160, value = 1024, step = 1, interactive = True, label = "Height" )
width = gr.Slider( minimum = 144, maximum = 2160, value = 1024, step = 1, interactive = True, label = "Width" )
nis = gr.Slider( minimum = 0, maximum = 100, value = 50, step = 1, interactive = True, label = "Steps" )
gs = gr.Slider( minimum = 0, maximum = 100, value = 7.5, step = 0.001, interactive = True, label = "Guidance" )
seed = gr.Slider( minimum = 0, maximum = 9007199254740991, value = 42, step = 1, interactive = True, label = "Seed" )
with gr.Row():
with gr.Column():
output = gr.Image(label = "Output")
run.click(generate, inputs = [prompt_text, model, negative_prompt_text, height, width, nis, gs, seed], outputs = [output], queue = False)
maintain.click(cloud, inputs = [], outputs = [], queue = False)
demo.launch(show_api = True) |