akshayp's picture
arg
b1ebde3
import gradio as gr
import requests
import json
import os
def get_result(prompt):
API_URL = "https://api.supercanvas.ai/v1/run/2a2a2ee4-0c0a-4f6d-9ed3-510cb450a663"
payload = { "properties": {
"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("apple pie, 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=1):
image_output = gr.Image(value="https://storage.googleapis.com/ai-pipeline-app.appspot.com/qGv8tG1ZLxdsMIJIUtlVCg/031eab99-af5d-4d61-b824-51679444c675-0.png")
text_button.click(get_result, inputs=[prompt], outputs=image_output)
demo.queue()
demo.launch()