heaversm commited on
Commit
88c3112
·
1 Parent(s): bd81242

go back to random file names

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -4,8 +4,12 @@ import sys
4
  import zipfile
5
  import requests
6
  import tempfile
7
- import json
8
  from io import BytesIO
 
 
 
 
 
9
 
10
  # gradio / hf stuff
11
  import gradio as gr
@@ -69,9 +73,12 @@ def download_image(url):
69
  def zip_images(image_paths_and_labels):
70
  zip_file_path = tempfile.NamedTemporaryFile(delete=False, suffix='.zip').name
71
  with zipfile.ZipFile(zip_file_path, 'w') as zipf:
72
- for image_url, label in image_paths_and_labels:
73
  image_content = download_image(image_url)
74
- zipf.writestr(label + ".png", image_content)
 
 
 
75
  return zip_file_path
76
 
77
 
@@ -136,7 +143,7 @@ with gr.Blocks() as demo:
136
  text = gr.Textbox(label="What do you want to create?",
137
  placeholder="Enter your text and then click on the \"Image Generate\" button")
138
 
139
- model = gr.Dropdown(choices=["dall-e-2", "dall-e-3"], label="Model", value="dall-e-3")
140
  btn = gr.Button("Generate Images")
141
  output_images = gr.Gallery(label="Image Outputs", show_label=True, columns=[3], rows=[1], object_fit="contain",
142
  height="auto", allow_preview=False)
 
4
  import zipfile
5
  import requests
6
  import tempfile
 
7
  from io import BytesIO
8
+ import random
9
+ import string
10
+
11
+ #image generation stuff
12
+ from PIL import Image
13
 
14
  # gradio / hf stuff
15
  import gradio as gr
 
73
  def zip_images(image_paths_and_labels):
74
  zip_file_path = tempfile.NamedTemporaryFile(delete=False, suffix='.zip').name
75
  with zipfile.ZipFile(zip_file_path, 'w') as zipf:
76
+ for image_url, _ in image_paths_and_labels:
77
  image_content = download_image(image_url)
78
+ # Generate a random filename for the image
79
+ random_filename = ''.join(random.choices(string.ascii_letters + string.digits, k=10)) + ".png"
80
+ # Write the image content to the zip file with the random filename
81
+ zipf.writestr(random_filename, image_content)
82
  return zip_file_path
83
 
84
 
 
143
  text = gr.Textbox(label="What do you want to create?",
144
  placeholder="Enter your text and then click on the \"Image Generate\" button")
145
 
146
+ model = gr.Dropdown(choices=["dall-e-2", "dall-e-3"], label="Model", value="dall-e-2")
147
  btn = gr.Button("Generate Images")
148
  output_images = gr.Gallery(label="Image Outputs", show_label=True, columns=[3], rows=[1], object_fit="contain",
149
  height="auto", allow_preview=False)