Spaces:
Runtime error
Runtime error
File size: 7,645 Bytes
6a20884 f1f83f2 6d8c23b 6a20884 f1f83f2 6a20884 67b8f97 6a20884 67b8f97 953f4c0 2083734 67b8f97 104aedd 6a20884 6d8c23b 67b8f97 2083734 67b8f97 6d8c23b 67b8f97 6d8c23b 6a20884 42ce8e5 fe27883 42ce8e5 fe27883 630f7c7 42ce8e5 6a20884 630f7c7 6a20884 a117519 6a20884 a117519 6a20884 67b8f97 a117519 67b8f97 a117519 67b8f97 6a20884 6d8c23b 6a20884 5bdb7ed 67b8f97 6d8c23b 67b8f97 6d8c23b 67b8f97 6d8c23b 67b8f97 6d8c23b 67b8f97 953f4c0 6a20884 67b8f97 6a20884 42ce8e5 |
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
import gradio as gr
import requests
import time
import requests
import base64
import os
token = os.getenv("runpod_key")
#############################################################
#################################################
def SD_call(prompt, image_prompt, age, weight, w_w, color, hair_color,h_c_w, hair_length, h_l_w,hair_texture, h_t_w,skin_details, eye_colors, e_c_w,NSFW):
positive = "clothes"
negative = "(((naked))), (((nsfw))), porn"
serverless_api_id = 'zcparyadhjnmg7'
# Define the URL you want to send the request to
url = f"https://api.runpod.ai/v2/{serverless_api_id}/runsync"
# Define your custom headers
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/json",
"Content-Type": "application/json"
}
weight = f"{'(' * w_w}{weight} woman{')' * w_w}"
hair_color=f"{'(' * h_c_w}{hair_color} hair{')' * h_c_w}"
hair_length=f"{'(' * h_l_w}{hair_length} hair{')' * h_l_w}"
hair_texture =f"{'(' * h_t_w}{hair_texture} hair{')' * h_t_w}"
eye_colors=f"{'(' * e_c_w}{eye_colors} eyes{')' * e_c_w}"
if NSFW == True:
positive = "((naked)), ((nsfw))"
negative = "((clothes))"
if prompt.strip():
total_prompt = prompt
else:
color = ", ".join(color)
skin_details = ", ".join(skin_details)
total_prompt = f"masterpiece, best quality, 8k, (looking at viewer:1.1), gorgeous, hot, seductive, {age} years old american {color} woman, {weight}, (eye contact:1.1), beautiful face, hyper detailed, best quality, ultra high res, {hair_length}, {hair_color}, {hair_texture},{eye_colors}, {skin_details}, photorealistic, high resolution, detailed, raw photo, 1girl,{image_prompt}, amateur cellphone photography. f8.0, samsung galaxy, noise, jpeg artefacts, poor lighting, low light, underexposed, high contrast "
# Define your data (this could also be a JSON payload)
print("SD_processing")
data = {
"input": {
"api": {
"method": "POST",
"endpoint": "/sdapi/v1/txt2img"
},
"payload": {
"override_settings": {
"sd_model_checkpoint": "CyberRealistic",
"sd_vae": ""
},
"override_settings_restore_afterwards": True,
"refiner_checkpoint": "",
"refiner_switch_at": 0.8,
"prompt": f"{total_prompt}, {positive}",
"negative_prompt": f"EasyNegative, fat, paintings, sketches, lowres, ((monochrome)), ((grayscale)), bad anatomy, text, error, cropped, signature, watermark, username, blurry, bad feet, poorly drawn face, bad proportions, gross proportions, ng_deepnegative_v1_75t, badhandsv5-neg, {negative}",
"seed": -1,
"batch_size": 1,
"steps": 30,
"cfg_scale": 7,
"width": 520,
"height": 520,
"sampler_name": "DPM++ SDE Karras",
"sampler_index": "DPM++ SDE Karras",
"restore_faces": False
}
}
}
# data = {
# "input": {
# "prompt": f"{total_prompt}, {positive}",
# "negative_prompt": f"paintings, sketches, lowres, ((monochrome)), ((grayscale)), bad anatomy, text, error, cropped, signature, watermark, username, blurry, bad feet, poorly drawn face, bad proportions, gross proportions, badhandsv5-neg, {negative}",
# "width": 512,
# "height": 720,
# "guidance_scale": 7.5,
# "num_inference_steps": 30,
# "num_outputs": 1,
# "prompt_strength": 0.8,
# "scheduler": "K-LMS"
# }
# }
# Send the POST request with headers and data
response = requests.post(url, headers=headers, json=data)
# Check the response
if response.status_code == 200:
response_data = response.json()
msg_id = response_data['id']
print("Message ID:", msg_id)
# Poll the status until it's not 'IN_QUEUE'
while response_data['status'] == 'IN_QUEUE':
time.sleep(5) # Wait for 5 seconds before checking again
print("1")
response = requests.get(f"{url}/{msg_id}", headers=headers)
try:
response_data = response.json()
except Exception as e:
print("Error decoding JSON:", e)
print("Response content:", response.text)
break # Exit the loop on JSON decoding error
# Check if the response contains images
if 'images' in response_data.get('output', {}):
print("image")
base64_image = response_data['output']['images'][0]
image_bytes = base64.b64decode(base64_image)
# Save the image to a file
image_path = f"output_image_{msg_id}.png"
with open(image_path, "wb") as img_file:
img_file.write(image_bytes)
print(f"Image downloaded successfully: {image_path}")
return image_path
else:
return "No images found in the response."
else:
# Print error message
return f"Error: {response.status_code} - {response.text}"
def greet(prompt, image_prompt, age, weight, w_w, color, hair_color, h_c_w, hair_length, h_l_w,hair_texture, h_t_w,skin_details, eye_colors, e_c_w,NSFW):
image_path = SD_call(prompt, image_prompt, age, weight, w_w, color, hair_color,h_c_w, hair_length, h_l_w,hair_texture, h_t_w,skin_details, eye_colors, e_c_w,NSFW)
if image_path is not None:
return image_path
else:
return None
demo = gr.Interface(
fn=greet,
inputs=[
gr.Textbox(label="Personal prompt", lines=3),
gr.Textbox(label="Girl_prompt", lines=3),
gr.Slider(label="Age", value=22, minimum=18, maximum=75),
gr.Radio(["skinny", "slim", "athletic", "muscular", "average", "curvy", "chubby", "overweight", "obese"],label="Body Type",type="value"),
gr.Slider(label="Body Type weight", value=2, minimum=1, maximum=4, step=1),
gr.CheckboxGroup(choices=["asian", "white", "black", "latina", "middle eastern","indigenous", "Mixed"],label="Color",type="value"),
gr.Radio(["black", "brown", "brunette", "dark brown", "light brown", "blonde", "dirty blonde", "platinum blonde", "red", "auburn", "ginger", "strawberry blonde", "gray", "silver", "white", "blue", "green", "purple", "pink", "rainbow", "multicolored"],label="Hair Color",type="value"),
gr.Slider(label="Hair Color weight", value=2, minimum=1, maximum=4, step=1),
gr.Radio(["short", "long", "mi-long"],label="Hair length", type="value"),
gr.Slider(label="Hair length weight", value=2, minimum=1, maximum=4, step=1),
gr.Radio(["straight", "curvy", "wavy"],label="Hair texture", type="value"),
gr.Slider(label="Hair texture weight", value=2, minimum=1, maximum=4, step=1),
gr.CheckboxGroup(choices=["((tattoos))", "((birthmark))", "freckles", "((scars))"],label="Skin details", type="value"),
gr.Radio(["brown", "hazel", "green", "blue", "gray", "amber", "black", "red", "violet"],label="Eyes Color", type="value"),
gr.Slider(label="Eyes color weight", value=2, minimum=1, maximum=4, step=1),
gr.Checkbox(label="NSFW", info="πππ")
],
flagging_options=["blurry", "incorrect", "other"],
outputs=[gr.Image(label="Generated Image", type="filepath")],
)
demo.launch(share=True) |