Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,17 +11,26 @@ from openai import OpenAI
|
|
| 11 |
# im1.save(r'new_name.png')
|
| 12 |
# return im1
|
| 13 |
def create_var(image_path, open_api_key):
|
|
|
|
|
|
|
| 14 |
client = OpenAI(api_key = open_api_key)
|
| 15 |
# image2 = con_image("white_tile.jpg")
|
| 16 |
response = client.images.create_variation(
|
| 17 |
image=open(image_path, "rb"),
|
| 18 |
-
n=
|
| 19 |
size="1024x1024"
|
| 20 |
)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
block = gr.Blocks(theme=gr.themes.Glass(primary_hue="slate"))
|
| 27 |
with block:
|
|
@@ -32,6 +41,6 @@ with block:
|
|
| 32 |
api_input = gr.Textbox(label= "Enter Api-key")
|
| 33 |
upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
|
| 34 |
with gr.Column():
|
| 35 |
-
|
| 36 |
-
upload_button.click(create_var, inputs=[img_input, api_input], outputs=[
|
| 37 |
block.launch()
|
|
|
|
| 11 |
# im1.save(r'new_name.png')
|
| 12 |
# return im1
|
| 13 |
def create_var(image_path, open_api_key):
|
| 14 |
+
url_list = []
|
| 15 |
+
img_list = []
|
| 16 |
client = OpenAI(api_key = open_api_key)
|
| 17 |
# image2 = con_image("white_tile.jpg")
|
| 18 |
response = client.images.create_variation(
|
| 19 |
image=open(image_path, "rb"),
|
| 20 |
+
n=4,
|
| 21 |
size="1024x1024"
|
| 22 |
)
|
| 23 |
+
for i in range(len(response.data)):
|
| 24 |
+
url1 = response.data[i].url
|
| 25 |
+
url_list.append(url1)
|
| 26 |
+
|
| 27 |
+
for j in range(len(url_list)) :
|
| 28 |
+
response = requests.get(url_list[j])
|
| 29 |
+
with open(f"image{j}.jpg", "wb") as f:
|
| 30 |
+
f.write(response.content)
|
| 31 |
+
img_list.append(f"image{j}.jpg")
|
| 32 |
+
return img_list
|
| 33 |
+
|
| 34 |
|
| 35 |
block = gr.Blocks(theme=gr.themes.Glass(primary_hue="slate"))
|
| 36 |
with block:
|
|
|
|
| 41 |
api_input = gr.Textbox(label= "Enter Api-key")
|
| 42 |
upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
|
| 43 |
with gr.Column():
|
| 44 |
+
img_gallery = gr.Gallery(label="Generated images", show_label=True, elem_id="gallery", object_fit="contain", height="auto",allow_preview=True)
|
| 45 |
+
upload_button.click(create_var, inputs=[img_input, api_input], outputs=[img_gallery])
|
| 46 |
block.launch()
|