Spaces:
Runtime error
Runtime error
File size: 2,250 Bytes
04e4010 d764277 04e4010 |
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 |
import asyncio
import io
import json
import os
import aiohttp
from PIL import Image
from dotenv import load_dotenv
load_dotenv()
import PIL
API_URL = os.getenv("API_URL")
API_KEY = os.getenv("API_KEY")
import gradio as gr
async def load_image_from_url(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
image_data = await response.read()
return Image.open(io.BytesIO(image_data))
async def greet(prompt):
url = API_URL
headers = {
'x-qrbtf-key': f'{API_KEY}',
}
full_response: str = ""
payload = {
'url': 'https://qrbtf.com/',
'prompt': prompt,
}
async with aiohttp.ClientSession(headers=headers) as session:
async with session.post(url, json=payload, ssl=False) as response:
await asyncio.sleep(0)
async for (chunk, _) in response.content.iter_chunks():
chunk = json.loads(chunk.decode("utf-8"))
if chunk["type"] == "result":
data = chunk["data"]
url = data["download_url"]
print(url)
return await load_image_from_url(url)
return full_response
with gr.Blocks() as demo:
gr.Markdown("""
# QRBTF.AI API Demo
- [Join Discord](https://discord.gg/V9CNuqYfte)
- [Official website](https://qrbtf.com/)
""")
with gr.Row():
with gr.Column():
url = gr.Textbox(
label="URL",
placeholder="https://",
value="https://qrbtf.com/",
interactive=False
)
prompt = gr.Textbox(
label="Prompt",
placeholder="Enter a prompt here",
value="1girl, flowers, birds",
)
with gr.Row():
clear_btn = gr.Button(
"Clear",
)
btn = gr.Button(
"Call API",
variant="primary"
)
with gr.Column():
out = gr.Image()
btn.click(fn=greet, inputs=prompt, outputs=out)
clear_btn.click(fn=lambda: prompt.update(""))
demo.launch()
|