Spaces:
Runtime error
Runtime error
dovedovepigeon
commited on
Commit
•
b473941
1
Parent(s):
34b32a1
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,6 @@ from PIL import Image, ImageDraw
|
|
6 |
import io
|
7 |
import requests
|
8 |
|
9 |
-
openai.organization = os.getenv("API_ORG")
|
10 |
-
openai.api_key = os.getenv("API_KEY")
|
11 |
-
app_password = os.getenv("APP_PASSWORD")
|
12 |
-
app_username = os.getenv("APP_USERNAME")
|
13 |
canvas_width = 500
|
14 |
canvas_height = 400
|
15 |
|
@@ -132,7 +128,9 @@ def gen_mask(image, left, top, right, bottom):
|
|
132 |
)
|
133 |
return mask
|
134 |
|
135 |
-
def create_edit(image, rect, prompt):
|
|
|
|
|
136 |
rect = json.loads(rect)
|
137 |
image.putalpha(alpha=255)
|
138 |
square_image = expand2square(image, "black")
|
@@ -160,6 +158,9 @@ def create_edit(image, rect, prompt):
|
|
160 |
return croped_edited_image
|
161 |
|
162 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
163 |
with gr.Column():
|
164 |
with gr.Row():
|
165 |
with gr.Column():
|
@@ -195,7 +196,7 @@ with gr.Blocks() as demo:
|
|
195 |
btn = gr.Button(value="Image Edit")
|
196 |
rect_text = gr.Textbox(elem_id="rectangle", visible=False)
|
197 |
in_image.change(None, inputs=None, outputs=None, _js=image_change)
|
198 |
-
btn.click(create_edit, inputs=[in_image, rect_text, prompt_text], outputs=[out_image])
|
199 |
demo.load(_js=scripts)
|
200 |
|
201 |
-
demo.launch(
|
|
|
6 |
import io
|
7 |
import requests
|
8 |
|
|
|
|
|
|
|
|
|
9 |
canvas_width = 500
|
10 |
canvas_height = 400
|
11 |
|
|
|
128 |
)
|
129 |
return mask
|
130 |
|
131 |
+
def create_edit(image, rect, prompt, api_key, api_organization=None):
|
132 |
+
openai.organization = api_organization
|
133 |
+
openai.api_key = api_key
|
134 |
rect = json.loads(rect)
|
135 |
image.putalpha(alpha=255)
|
136 |
square_image = expand2square(image, "black")
|
|
|
158 |
return croped_edited_image
|
159 |
|
160 |
with gr.Blocks() as demo:
|
161 |
+
with gr.Accordion("OpenAI API Settings", open=False):
|
162 |
+
api_key = gr.Textbox(label="OpenAI API key", placeholder="OpenAI API key")
|
163 |
+
api_organization = gr.Textbox(label="OpenAI API organization", placeholder="OpenAI API organization (optional)")
|
164 |
with gr.Column():
|
165 |
with gr.Row():
|
166 |
with gr.Column():
|
|
|
196 |
btn = gr.Button(value="Image Edit")
|
197 |
rect_text = gr.Textbox(elem_id="rectangle", visible=False)
|
198 |
in_image.change(None, inputs=None, outputs=None, _js=image_change)
|
199 |
+
btn.click(create_edit, inputs=[in_image, rect_text, prompt_text, api_key, api_organization], outputs=[out_image])
|
200 |
demo.load(_js=scripts)
|
201 |
|
202 |
+
demo.launch()
|