Spaces:
Runtime error
Runtime error
| 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() |