akshayp's picture
fix error
ca555c3
import gradio as gr
import requests
import json
import os
def get_result(prompt):
API_URL = "https://api.supercanvas.ai/v1/run/dfd23676-575c-498a-84f4-10d19af1e65b"
payload = { "properties": {
"user_prompt": prompt
}}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": f"Bearer {os.getenv('SUPERCANVAS_API_TOKEN')}"
}
response = requests.post(API_URL, json=payload, headers=headers)
result = response.json()
return result["output"]["urls"][0]
css = """
#generate {
height: 100%;
}
"""
with gr.Blocks(css=css) as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown(elem_id="powered-by-supercanvas-ai", value="Powered by [SuperCanvas.AI](https://www.supercanvas.ai/).")
with gr.Tab("Prompt"):
with gr.Row():
with gr.Column(scale=6, min_width=600):
prompt = gr.Textbox("hogwarts school of witchcraft and wizardry, 8k", placeholder="Prompt", show_label=False, lines=3)
with gr.Column():
text_button = gr.Button("Generate", variant='primary', elem_id="generate")
with gr.Row():
with gr.Column(scale=2):
image_output = gr.Image(value="https://storage.googleapis.com/ai-pipeline-app.appspot.com/JGoawqXDF1x2zKuKXj8ZWg/95bdb06c-03a5-4902-a0a0-0d5a206f4ca1-0.png")
text_button.click(get_result, inputs=[prompt], outputs=image_output)
demo.queue(concurrency_count=24)
demo.launch()