Spaces:
Sleeping
Sleeping
File size: 844 Bytes
662609f eb357c6 08b3c57 7a4be7f 08b3c57 7a4be7f 08b3c57 7a4be7f eb357c6 d882530 eb357c6 37ee6de 7a4be7f 08b3c57 47f7f63 b636da7 7a4be7f 252a108 3c39bfa 45e53f7 7a4be7f 45e53f7 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 |
import gradio_client
from gradio_client import Client, file
from urllib.parse import quote
from huggingface_hub import InferenceClient
import numpy as np
import gradio as gr
client = InferenceClient()
def generate_img(prompt):
return client.text_to_image(prompt)
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):
result = client.image_to_text(img)
return result['generated_text']
def rountrip(img):
prompt=interrogate(img)
print(prompt)
url=pollinations_url_seedless(prompt)
return generate_img(prompt),prompt,url
demo = gr.Interface(rountrip, gr.Image(type= 'filepath'),[gr.Image(type= 'filepath'),"textbox",gr.Image()])
demo.launch()
|