Spaces:
Running
Running
import gradio as gr | |
import requests | |
def generate_image(prompt): | |
apiUrl = 'https://apiv2.makeai.run/v2/txt2img' # Replace with your API URL | |
data = { | |
"mode": "url", | |
"model": "AOM3A1B_orangemixs.safetensors", | |
"tiling": false, | |
"batch_size": 1, | |
"prompt": prompt, | |
"negative_prompt": "worst quality, lowres", | |
"seed": 1234, | |
"scheduler": "Euler a", | |
"n_iter": 1, | |
"steps": 30, | |
"cfg": 11.0, | |
"offset_noise": 0.0, | |
"width": 1024, | |
"height": 1024, | |
"clip_skip": 1, | |
"loras": [ | |
{ | |
"name": "", | |
"strength": 1.0 | |
} | |
], | |
"embeddings": [ | |
{ | |
"name": "", | |
"strength": 1.0 | |
} | |
], | |
"vae": "vae-ft-mse-840000-ema-pruned.ckpt", | |
"restore_faces": false, | |
"fr_model": "CodeFormer", | |
"codeformer_weight": 0.5, | |
"enable_hr": false, | |
"denoising_strength": 0.75, | |
"hr_scale": 2, | |
"hr_upscale": "None", | |
"img2img_ref_img_type": "piece", | |
"img2img_resize_mode": 0, | |
"img2img_denoising_strength": 0.75, | |
"controlnet_enabled": false, | |
"controlnet_ref_img_type": "piece", | |
"controlnet_guessmode": false, | |
"controlnet_module": "canny", | |
"controlnet_model": "control_v11p_sd15_softedge", | |
"controlnet_weight": 1, | |
"controlnet_guidance_start": 0, | |
"controlnet_guidance_end": 1, | |
"controlnet_ref_img_url": "", | |
# Replace with your control image URL if needed | |
# https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png | |
# is used by default | |
# otherwise leave it blank | |
# or use the control image component below | |
# to upload an image from the interface | |
# and pass it as an argument to the function | |
# along with the prompt | |
# and set it as the value of this key | |
# in the data object | |
# before making the API call | |
# (see commented code below) | |
"controlnet_mask": [], | |
"controlnet_resize_mode": "Scale to Fit (Inner Fit)", | |
"controlnet_lowvram": false, | |
"controlnet_processor_res": 512, | |
"controlnet_threshold_a": 100, | |
"controlnet_threshold_b": 200 | |
} | |
headers = { | |
'Content-Type': 'application/json', | |
'token': '514f7ecde6a5434dbab5c6579311ad82' # Replace with your API token | |
} | |
response = requests.post(apiUrl, json=data, headers=headers) | |
responseData = response.json() | |
if responseData and responseData['results'] and responseData['results'][0]: | |
return responseData['results'][0] | |
else: | |
return "No image generated" | |
# Uncomment the following lines if you want to use the control image component | |
# def generate_image(prompt, control_image): | |
# apiUrl = 'https://apiv2.makeai.run/v2/txt2img' # Replace with your API URL | |
# data = { | |
# ... | |
# "controlnet_ref_img_url": control_image, | |
# ... | |
# } | |
# headers = { | |
# ... | |
# } | |
# response = requests.post(apiUrl, json=data, headers=headers) | |
# responseData = response.json() | |
# if responseData and responseData['results'] and responseData['results'][0]: | |
# return responseData['results'][0] | |
# else: | |
# return "No image generated" | |
title = gr.outputs.Textbox(label="Freedom Demonstration") | |
prompt = gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here", label="Prompt") | |
image = gr.outputs.Image(label="Generated Image") | |
# Uncomment the following line if you want to use the control image component | |
# control_image = gr.inputs.Image(label="Control Image (optional)") | |
iface = gr.Interface( | |
fn=generate_image, | |
inputs=[prompt], # Add control_image to the list if you want to use it | |
outputs=[title, image], | |
title="Freedom Demonstration", | |
description="This is a Gradio app that uses an API to generate images based on text prompts.", | |
live=False, | |
layout="vertical" | |
) | |
iface.launch() |