akshayp commited on
Commit
7f17e93
·
1 Parent(s): 32fef81

initial commit

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+ import os
5
+
6
+ def get_result(prompt):
7
+
8
+ API_URL = os.getenv('API_URL')
9
+
10
+ payload = { "properties": {
11
+ "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 {
28
+ height: 100%;
29
+ }
30
+ """
31
+
32
+ with gr.Blocks(css=css) as demo:
33
+
34
+
35
+ with gr.Row():
36
+ with gr.Column(scale=1):
37
+ gr.Markdown(elem_id="powered-by-supercanvas-ai", value="Powered by [SuperCanvas.AI](https://www.supercanvas.ai/).")
38
+
39
+ with gr.Tab("Prompt"):
40
+ with gr.Row():
41
+ with gr.Column(scale=6, min_width=600):
42
+ prompt = gr.Textbox(os.getenv('PLACEHOLDER_PROMPT'), placeholder="Prompt", show_label=False, lines=3)
43
+ with gr.Column():
44
+ text_button = gr.Button("Generate", variant='primary', elem_id="generate")
45
+
46
+ with gr.Row():
47
+
48
+ with gr.Column(scale=0.5):
49
+ image_output = gr.Image(value=os.getenv('PLACEHOLDER_IMG'))
50
+
51
+ text_button.click(get_result, inputs=[prompt], outputs=image_output)
52
+
53
+ demo.queue()
54
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ numpy
2
+ gradio
3
+ requests