Spaces:
Runtime error
Runtime error
File size: 3,627 Bytes
8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b d8785cf 8b1029b bf766c3 8b1029b 410ba09 cfe183b |
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 |
import gradio as gr
import requests
import time
import json
from contextlib import closing
from websocket import create_connection
from deep_translator import GoogleTranslator
from langdetect import detect
import os
from PIL import Image
import io
import base64
def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
result = {"prompt": prompt, "negative_prompt": negative_prompt, "task": task, "steps": steps, "sampler": sampler, "cfg_scale": cfg_scale, "seed": seed}
print(result)
language = detect(prompt)
if language == 'ru':
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
print(prompt)
cfg = int(cfg_scale)
steps = int(steps)
seed = int(seed)
url_sd1 = "https://stable-diffusion-open.api.replicate.com/infer"
url_sd2 = "https://api.replicate.com/predictions/10720/jobs/"
url_sd3 = "https://stable-diffusion-open.api.replicate.com/predictions/10720/output/"
if task == 'Realistic Vision 5.0':
model = 'Realistic Vision V5.0.safetensors+%5B614d1063%5D'
elif task == 'Dreamshaper 8':
model = 'dreamshaper_8.safetensors+%5B9d40847d%5D'
elif task == 'Deliberate 3':
model = 'deliberate_v3.safetensors+%5Bafd9d2d4%5D'
elif task == 'Analog Diffusion':
model = 'analog-diffusion-1.0.ckpt+%5B9ca13f02%5D'
elif task == 'Lyriel 1.6':
model = 'lyriel_v16.safetensors+%5B68fceea2%5D'
elif task == "Elldreth's Vivid Mix":
model = 'elldreths-vivid-mix.safetensors+%5B342d9d26%5D'
elif task == 'Anything V5':
model = 'anything-v4.5-pruned.ckpt+%5B65745d25%5D'
elif task == 'Openjourney V4':
model = 'openjourney_V4.ckpt+%5Bca2f377f%5D'
elif task == 'AbsoluteReality 1.8.1':
model = 'absolutereality_v181.safetensors+%5B3d9d4d2b%5D'
elif task == 'epiCRealism v5':
model = 'epicrealism_naturalSinRC1VAE.safetensors+%5B90a4c676%5D'
elif task == 'CyberRealistic 3.3':
model = 'cyberrealistic_v33.safetensors+%5B82b0d085%5D'
elif task == 'ToonYou 6':
model = 'toonyou_beta6.safetensors+%5B980f6b15%5D'
c = 0
r = requests.get(f'{url_sd1}?prompt={prompt}&model={model}&negative_prompt={negative_prompt}&steps={steps}&cfg={cfg}&seed={seed}&sampler={sampler}&aspect_ratio=square', timeout=10)
job = r.json()['job']
while c < 10:
c += 1
time.sleep(2)
r2 = requests.get(f'{url_sd2}{job}', timeout=10)
status = r2.json()['status']
if status == 'succeeded':
photo = f'{url_sd3}{job}.png'
return photo
if status == "queued":
continue
if status == 'failed':
return None
def mirror(image_output, scale_by, method, gfpgan, codeformer):
url_up = "https://scale-diffusion-open.api.replicate.com/infer"
url_up_f = "https://scale-diffusion-open.api.replicate.com/output/"
scale_by = int(scale_by)
gfpgan = int(gfpgan)
codeformer = int(codeformer)
with open(image_output, "rb") as image_file:
encoded_string2 = base64.b64encode(image_file.read())
encoded_string2 = str(encoded_string2).replace("b'", '')
encoded_string2 = "data:image/png;base64," + encoded_string2
data = {
"fn_index": 81,
"data": [0, 0, encoded_string2, None, "", "", True, gfpgan, codeformer, 0, scale_by, 512, 512, None, method, "None", 1, False, [], "", ""],
"session_hash": ""
}
r = requests.post(f"{url_up}", json=data, timeout=100)
print(r.text)
ph = f"{url_up_f}" + str(r.json()['data'][0][0]['name'])
return ph
|