gaur3009 commited on
Commit
db21836
·
verified ·
1 Parent(s): 8921df0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -16
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 single {color_prompt} colored {dress_type_prompt} featuring a bold {design_prompt} design printed on the {dress_type_prompt}, hanging on a plain wall. The soft light and shadows, creating a striking contrast against the minimal background, evoking modern sophistication.")
13
- full_prompt = f"{prompt}"
14
-
15
- print("Generating image with prompt:", full_prompt)
 
 
 
16
  api_url = f"https://api-inference.huggingface.co/models/{repo}"
17
- #token = os.getenv("API_TOKEN") # Uncomment and use your Hugging Face API token
18
- headers = {
19
- #"Authorization": f"Bearer {token}"
20
- }
21
  payload = {
22
- "inputs": full_prompt,
23
  "parameters": {
24
- "negative_prompt": "(worst quality, low quality, normal quality, lowres, low details, oversaturated, undersaturated, overexposed, underexposed, grayscale, bw, bad photo, bad photography, bad art:1.4), (watermark, signature, text font, username, error, logo, words, letters, digits, autograph, trademark, name:1.2), (blur, blurry, grainy), morbid, ugly, asymmetrical, mutated malformed, mutilated, poorly lit, bad shadow, draft, cropped, out of frame, cut off, censored, jpeg artifacts, out of focus, glitch, duplicate, (airbrushed, cartoon, anime, semi-realistic, cgi, render, blender, digital art, manga, amateur:1.3), (3D ,3D Game, 3D Game Scene, 3D Character:1.1), (bad hands, bad anatomy, bad body, bad face, bad teeth, bad arms, bad legs, deformities:1.3), (Poor Fit, ill-fitting, awkward proportions, baggy where it shouldn't be, tight in wrong places, Bad Texture, low-quality fabric, wrinkled, rough texture, pixelated details, artificial shine, Cluttered Design, overly busy, too many patterns, excessive contrast, distracting elements, Outdated Fashion, old-fashioned, style(unless intentional), outdated trends, dull colors, Bad Composition, misaligned prints, asymmetrical in an unintentional way, weird placement of logos, Cheap Look, plastic-like fabric, low-quality print, faded colors, generic fast fashion, Unrealistic Details, floating textures, distorted logos, unnatural fabric folds, Unwanted Features, holes, rips, stains, unfinished seams, torn edges)",
 
25
  "num_inference_steps": 30,
26
- "scheduler": "DPMSolverMultistepScheduler"
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"), # color_prompt
54
- gr.Textbox(lines=1, placeholder="Dress Type Prompt"), # dress_type_prompt
55
- gr.Textbox(lines=2, placeholder="Design Prompt"), # design_prompt
56
- gr.Textbox(lines=1, placeholder="Text (Optional)"), # text
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()