Update app.py
Browse files
app.py
CHANGED
@@ -7,32 +7,39 @@ from tqdm import tqdm
|
|
7 |
import time
|
8 |
|
9 |
repo = "artificialguybr/TshirtDesignRedmond-V2"
|
|
|
10 |
def infer(color_prompt, dress_type_prompt, design_prompt, text):
|
|
|
11 |
prompt = (
|
12 |
-
f"A
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
api_url = f"https://api-inference.huggingface.co/models/{repo}"
|
17 |
-
|
18 |
-
headers = {
|
19 |
-
|
20 |
-
}
|
21 |
payload = {
|
22 |
-
"inputs":
|
23 |
"parameters": {
|
24 |
-
|
|
|
25 |
"num_inference_steps": 30,
|
26 |
-
"scheduler": "
|
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))
|
@@ -50,10 +57,10 @@ def infer(color_prompt, dress_type_prompt, design_prompt, text):
|
|
50 |
iface = gr.Interface(
|
51 |
fn=infer,
|
52 |
inputs=[
|
53 |
-
gr.Textbox(lines=1, placeholder="Color Prompt"),
|
54 |
-
gr.Textbox(lines=1, placeholder="Dress Type Prompt"),
|
55 |
-
gr.Textbox(lines=2, placeholder="Design Prompt"),
|
56 |
-
gr.Textbox(lines=1, placeholder="Text (Optional)"),
|
57 |
],
|
58 |
outputs="image",
|
59 |
title="Make your Brand",
|
@@ -62,4 +69,4 @@ iface = gr.Interface(
|
|
62 |
)
|
63 |
|
64 |
print("Launching Gradio interface...")
|
65 |
-
iface.launch()
|
|
|
7 |
import time
|
8 |
|
9 |
repo = "artificialguybr/TshirtDesignRedmond-V2"
|
10 |
+
|
11 |
def infer(color_prompt, dress_type_prompt, design_prompt, text):
|
12 |
+
# Improved prompt for higher accuracy
|
13 |
prompt = (
|
14 |
+
f"A high-quality digital image of a {color_prompt} {dress_type_prompt}, "
|
15 |
+
f"featuring a {design_prompt} printed in sharp detail. The fabric has realistic texture, "
|
16 |
+
f"smooth folds, and accurate lighting. The design is perfectly aligned, with natural shadows "
|
17 |
+
f"and highlights, creating a photorealistic look."
|
18 |
+
)
|
19 |
+
|
20 |
+
print("Generating image with prompt:", prompt)
|
21 |
api_url = f"https://api-inference.huggingface.co/models/{repo}"
|
22 |
+
|
23 |
+
headers = {} # If API token needed, add here
|
24 |
+
|
|
|
25 |
payload = {
|
26 |
+
"inputs": prompt,
|
27 |
"parameters": {
|
28 |
+
# Optimized negative prompt
|
29 |
+
"negative_prompt": "low quality, artifacts, distorted, blurry, overexposed, underexposed, unrealistic texture, poor lighting, misaligned print, plastic-like fabric, grainy, washed-out colors, 3D render, cartoon, digital art, watermark, bad anatomy, malformed, cluttered design",
|
30 |
"num_inference_steps": 30,
|
31 |
+
"scheduler": "EulerAncestralDiscreteScheduler" # Faster & more accurate scheduler
|
32 |
},
|
33 |
}
|
34 |
|
35 |
error_count = 0
|
36 |
pbar = tqdm(total=None, desc="Loading model")
|
37 |
+
|
38 |
while True:
|
39 |
print("Sending request to API...")
|
40 |
response = requests.post(api_url, headers=headers, json=payload)
|
41 |
print("API response status code:", response.status_code)
|
42 |
+
|
43 |
if response.status_code == 200:
|
44 |
print("Image generation successful!")
|
45 |
return Image.open(BytesIO(response.content))
|
|
|
57 |
iface = gr.Interface(
|
58 |
fn=infer,
|
59 |
inputs=[
|
60 |
+
gr.Textbox(lines=1, placeholder="Color Prompt"),
|
61 |
+
gr.Textbox(lines=1, placeholder="Dress Type Prompt"),
|
62 |
+
gr.Textbox(lines=2, placeholder="Design Prompt"),
|
63 |
+
gr.Textbox(lines=1, placeholder="Text (Optional)"),
|
64 |
],
|
65 |
outputs="image",
|
66 |
title="Make your Brand",
|
|
|
69 |
)
|
70 |
|
71 |
print("Launching Gradio interface...")
|
72 |
+
iface.launch()
|