rahul7star commited on
Commit
05cbff8
·
verified ·
1 Parent(s): e65f6f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -24
app.py CHANGED
@@ -10,8 +10,8 @@ import time
10
  repo = "stabilityai/stable-diffusion-xl-base-1.0"
11
  trigger_word = "T shirt design, TshirtDesignAF, "
12
 
13
- def generate_image(prompt):
14
- print("Generating image with prompt:", prompt)
15
  api_url = f"https://api-inference.huggingface.co/models/{repo}"
16
  #token = os.getenv("API_TOKEN") # Uncomment and use your Hugging Face API token
17
  headers = {
@@ -27,33 +27,39 @@ def generate_image(prompt):
27
  },
28
  }
29
 
30
- error_count = 0
31
- pbar = tqdm(total=None, desc="Loading model")
32
- while True:
33
- print("Sending request to API...")
34
- response = requests.post(api_url, headers=headers, json=payload)
35
- print("API response status code:", response.status_code)
36
- if response.status_code == 200:
37
- print("Image generation successful!")
38
- return Image.open(BytesIO(response.content)) # Changed to match the first code
39
- elif response.status_code == 503:
40
- time.sleep(1)
41
- pbar.update(1)
42
- elif response.status_code == 500 and error_count < 5:
43
- time.sleep(1)
44
- error_count += 1
45
- else:
46
- print("API Error:", response.status_code)
47
- raise Exception(f"API Error: {response.status_code}")
 
 
 
 
 
 
48
 
49
  iface = gr.Interface(
50
- fn=generate_image,
51
  inputs=gr.Textbox(lines=2, placeholder="Type your prompt here..."),
52
- outputs="image",
53
- title="Desgin by rahul7star",
54
  description="Make designs for your clothes",
55
  examples=[["Cute Panda"], ["Skull"]]
56
  )
57
 
58
  print("Launching Gradio interface...")
59
- iface.launch()
 
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 images with prompt:", prompt)
15
  api_url = f"https://api-inference.huggingface.co/models/{repo}"
16
  #token = os.getenv("API_TOKEN") # Uncomment and use your Hugging Face API token
17
  headers = {
 
27
  },
28
  }
29
 
30
+ images = []
31
+ for i in range(10):
32
+ error_count = 0
33
+ pbar = tqdm(total=None, desc=f"Loading model {i+1}/10")
34
+ while True:
35
+ print(f"Sending request to API for image {i+1}...")
36
+ response = requests.post(api_url, headers=headers, json=payload)
37
+ print("API response status code:", response.status_code)
38
+ if response.status_code == 200:
39
+ print(f"Image {i+1} generation successful!")
40
+ img = Image.open(BytesIO(response.content))
41
+ images.append(img)
42
+ break
43
+ elif response.status_code == 503:
44
+ time.sleep(1)
45
+ pbar.update(1)
46
+ elif response.status_code == 500 and error_count < 5:
47
+ time.sleep(1)
48
+ error_count += 1
49
+ else:
50
+ print(f"API Error for image {i+1}: {response.status_code}")
51
+ raise Exception(f"API Error: {response.status_code}")
52
+
53
+ return images
54
 
55
  iface = gr.Interface(
56
+ fn=generate_images,
57
  inputs=gr.Textbox(lines=2, placeholder="Type your prompt here..."),
58
+ outputs=gr.Gallery(label="Generated Images").style(grid=[5]), # Display images in a grid of 5 columns
59
+ title="Design by rahul7star",
60
  description="Make designs for your clothes",
61
  examples=[["Cute Panda"], ["Skull"]]
62
  )
63
 
64
  print("Launching Gradio interface...")
65
+ iface.launch()