Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
14 |
-
print("Generating
|
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 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
print("
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
iface = gr.Interface(
|
50 |
-
fn=
|
51 |
inputs=gr.Textbox(lines=2, placeholder="Type your prompt here..."),
|
52 |
-
outputs="
|
53 |
-
title="
|
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()
|