rahul7star commited on
Commit
80c342b
·
verified ·
1 Parent(s): 9da351a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -5,11 +5,16 @@ from PIL import Image
5
  from io import BytesIO
6
  from tqdm import tqdm
7
  import time
 
8
 
9
  # Defining the repository information and the trigger word
10
  repo = "stabilityai/stable-diffusion-xl-base-1.0"
11
  trigger_word = "T shirt design, TshirtDesignAF, "
12
 
 
 
 
 
13
  def generate_images(prompt):
14
  print("Generating 10 unique images with prompt:", prompt)
15
  api_url = f"https://api-inference.huggingface.co/models/{repo}"
@@ -20,7 +25,10 @@ def generate_images(prompt):
20
 
21
  images = []
22
  for i in range(10):
23
- full_prompt = f"{prompt} {trigger_word} unique_design_{i}"
 
 
 
24
  payload = {
25
  "inputs": full_prompt,
26
  "parameters": {
@@ -40,6 +48,11 @@ def generate_images(prompt):
40
  print(f"Image {i+1} generation successful!")
41
  img = Image.open(BytesIO(response.content))
42
  images.append(img)
 
 
 
 
 
43
  break
44
  elif response.status_code == 503:
45
  time.sleep(1)
 
5
  from io import BytesIO
6
  from tqdm import tqdm
7
  import time
8
+ import random
9
 
10
  # Defining the repository information and the trigger word
11
  repo = "stabilityai/stable-diffusion-xl-base-1.0"
12
  trigger_word = "T shirt design, TshirtDesignAF, "
13
 
14
+ # Directory to save images
15
+ output_dir = "saved_designs"
16
+ os.makedirs(output_dir, exist_ok=True) # Create directory if it doesn't exist
17
+
18
  def generate_images(prompt):
19
  print("Generating 10 unique images with prompt:", prompt)
20
  api_url = f"https://api-inference.huggingface.co/models/{repo}"
 
25
 
26
  images = []
27
  for i in range(10):
28
+ # Add a unique seed to each prompt to ensure different images
29
+ unique_seed = random.randint(1000, 9999)
30
+ full_prompt = f"{prompt} {trigger_word} seed_{unique_seed}"
31
+
32
  payload = {
33
  "inputs": full_prompt,
34
  "parameters": {
 
48
  print(f"Image {i+1} generation successful!")
49
  img = Image.open(BytesIO(response.content))
50
  images.append(img)
51
+
52
+ # Save the image to the output directory
53
+ img_filename = os.path.join(output_dir, f"{prompt.replace(' ', '_')}_design_{i+1}.png")
54
+ img.save(img_filename)
55
+ print(f"Image saved as: {img_filename}")
56
  break
57
  elif response.status_code == 503:
58
  time.sleep(1)