Testspace2 / app.py
AI-Journey2's picture
Update app.py
ab70f27 verified
raw
history blame
1.7 kB
import requests
from PIL import Image
import gradio as gr
from io import BytesIO
url = "https://stablediffusionapi.com/api/v3/text2img"
title = """<h2><center>Text to Image Generation with Stable Diffusion API</center></h2>"""
description = """#### Get the API key by signing up here [Stable Diffusion API](https://stablediffusionapi.com)."""
def get_image(key, prompt, inference_steps, filter):
payload = {
"key": key,
"prompt": prompt,
"negative_prompt": "((out of frame)), ((extra fingers)), mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), (((tiling))), ((naked)), ((tile)), ((fleshpile)), ((ugly)), (((abstract))), blurry, ((bad anatomy)), ((bad proportions)), ((extra limbs)), cloned face, (((skinny))), glitchy, ((extra breasts)), ((double torso)), ((extra arms)), ((extra hands)), ((mangled fingers)), ((missing breasts)), (missing lips), ((ugly face)), ((fat)), ((extra legs)), anime",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": inference_steps,"safety_checker": filter,"enhance_prompt": "yes","guidance_scale": 7.5}
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
url1 = str(json.loads(response.text)['output'][0])
r = requests.get(url1)
i = Image.open(BytesIO(r.content))
return i
demo = gr.Interface(fn=get_image,
inputs = [gr.Textbox(label="Enter API key"), gr.Textbox(label="Enter the Prompt"), gr.Number(label="Enter number of steps"),gr.Checkbox(label="Safety filter")],
outputs = gr.Image(type='pil'), title = title, description = description).launch(debug='True')