File size: 1,318 Bytes
662609f eb357c6 7a4be7f 37ee6de 7a4be7f eb357c6 d882530 eb357c6 37ee6de 7a4be7f d686bf8 7a4be7f 37ee6de 7a4be7f 6c0c804 7a4be7f 2455ada b636da7 7a4be7f 252a108 3c39bfa 252a108 7a4be7f b2675c2 7a4be7f |
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 |
import gradio_client
from gradio_client import Client, file
from urllib.parse import quote
import numpy as np
import gradio as gr
def generate_img(prompt):
client = Client("ameerazam08/SDXS-GPU-Demo")
client.view_api()
result = client.predict(
prompt=prompt,
api_name="/generate_image"
)
return result
def pollinations_url_seedless(a, width=512, height=512):
urlprompt=quote(str(a))
url=f"https://image.pollinations.ai/prompt/{urlprompt}?width={width}&height={height}"
return url
def interrogate(img):
from gradio_client import Client
# client = Client("fffiloni/CLIP-Interrogator-2")
# client.view_api()
client = Client("https://pharmapsychotic-clip-interrogator.hf.space/")
client.view_api()
result = client.predict(
img, # str (filepath or URL to image)
"ViT-L (best for Stable Diffusion 1.*)", # str (Option from: ['ViT-L (best for Stable Diffusion 1.*)'])
"best", # str in 'Mode' Radio component
fn_index=3
)
return result
def rountrip(img):
prompt=interrogate(img)
print(prompt)
url=pollinations_url_seedless(prompt)
return generate_img(prompt),prompt
demo = gr.Interface(rountrip, gr.Image(type= 'filepath'),[gr.Image(type= 'filepath'),"textbox"])
demo.launch()
|