cedpsam's picture
Update app.py
7921e85 verified
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
hfclient = InferenceClient()
grclient = Client("fancyfeast/joy-caption-alpha-two")
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 = grclient.predict(
input_image=file(img),
name_input="Hello!!",
custom_prompt="Analyze this image like an art critic would with information about its composition, style, symbolism, the use of color, light, any artistic movement it might belong to, etc. Keep it very long.",
api_name="/stream_chat"
)
return result[1]
def rountrip(img):
prompt=interrogate(img)
print(prompt)
url=pollinations_url_seedless(prompt)
return prompt,url
demo = gr.Interface(rountrip, gr.Image(type= 'filepath'),["textbox",gr.Image(label="pollination")])
demo.launch()