Spaces:
Running
Running
fix error
Browse files
app.py
CHANGED
|
@@ -1,46 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import time
|
| 4 |
import json
|
| 5 |
-
import base64
|
| 6 |
import os
|
| 7 |
-
from PIL import Image
|
| 8 |
-
from io import BytesIO
|
| 9 |
|
| 10 |
-
|
| 11 |
-
def __init__(self, api_key):
|
| 12 |
-
self.base = "https://api.supercanvas.ai/v1/run/dfd23676-575c-498a-84f4-10d19af1e65b"
|
| 13 |
-
self.headers = {
|
| 14 |
-
"accept": "application/json",
|
| 15 |
-
"content-type": "application/json",
|
| 16 |
-
"authorization": f"Bearer {api_key}"
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
def generate(self, prompt):
|
| 20 |
-
payload = { "properties": {
|
| 21 |
-
"user_prompt": prompt
|
| 22 |
-
}}
|
| 23 |
-
response = requests.post(self.base, json=payload, headers=self.headers)
|
| 24 |
-
return response.json()
|
| 25 |
-
|
| 26 |
-
def wait(self, job):
|
| 27 |
-
job_result = job
|
| 28 |
-
|
| 29 |
-
while job_result['status'] in ['running']:
|
| 30 |
-
time.sleep(0.25)
|
| 31 |
-
|
| 32 |
-
return job_result
|
| 33 |
|
|
|
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
result = supercanvas_client.generate(prompt)
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
return
|
| 44 |
|
| 45 |
css = """
|
| 46 |
#generate {
|
|
@@ -58,7 +39,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 58 |
with gr.Tab("Prompt"):
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column(scale=6, min_width=600):
|
| 61 |
-
prompt = gr.Textbox("hogwarts school", placeholder="Prompt", show_label=False, lines=3)
|
| 62 |
with gr.Column():
|
| 63 |
text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
| 64 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import json
|
|
|
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def get_result(prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
API_URL = "https://api.supercanvas.ai/v1/run/dfd23676-575c-498a-84f4-10d19af1e65b"
|
| 9 |
|
| 10 |
+
payload = { "properties": {
|
| 11 |
+
"user_prompt": prompt
|
| 12 |
+
}}
|
| 13 |
|
| 14 |
+
headers = {
|
| 15 |
+
"accept": "application/json",
|
| 16 |
+
"content-type": "application/json",
|
| 17 |
+
"authorization": f"Bearer {os.getenv('SUPERCANVAS_API_TOKEN')}"
|
| 18 |
+
}
|
| 19 |
|
| 20 |
+
response = requests.post(API_URL, json=payload, headers=headers)
|
|
|
|
| 21 |
|
| 22 |
+
result = response.json()
|
| 23 |
|
| 24 |
+
return result["output"]["urls"][0]
|
| 25 |
|
| 26 |
css = """
|
| 27 |
#generate {
|
|
|
|
| 39 |
with gr.Tab("Prompt"):
|
| 40 |
with gr.Row():
|
| 41 |
with gr.Column(scale=6, min_width=600):
|
| 42 |
+
prompt = gr.Textbox("hogwarts school of witchcraft and wizardry, 8k", placeholder="Prompt", show_label=False, lines=3)
|
| 43 |
with gr.Column():
|
| 44 |
text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
| 45 |
|