Spaces:
Runtime error
Runtime error
| 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 | |
| # Use a pipeline as a high-level helper | |
| from transformers import pipeline | |
| #from optimum.onnxruntime import pipeline | |
| pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large") | |
| 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 = pipe(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(label="pollination")]) | |
| demo.launch() | |