Spaces:
Runtime error
Runtime error
File size: 1,387 Bytes
7f17e93 |
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 |
import gradio as gr
import requests
import json
import os
def get_result(prompt):
API_URL = os.getenv('API_URL')
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(os.getenv('PLACEHOLDER_PROMPT'), 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=0.5):
image_output = gr.Image(value=os.getenv('PLACEHOLDER_IMG'))
text_button.click(get_result, inputs=[prompt], outputs=image_output)
demo.queue()
demo.launch() |