gaur3009 commited on
Commit
76f60f0
·
verified ·
1 Parent(s): c5a907c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -75
app.py CHANGED
@@ -1,26 +1,23 @@
1
  import gradio as gr
2
  import requests
3
- from PIL import Image, ImageOps, ImageChops
 
4
  from io import BytesIO
5
  from tqdm import tqdm
6
  import time
7
 
8
- # Repository information and trigger word
9
  repo = "artificialguybr/TshirtDesignRedmond-V2"
10
- dress_trigger = "Minimalist dress design, DressDesignAF"
11
- design_trigger = "Clothing design pattern, DesignPatternAF"
12
 
13
- def generate_image(prompt, style="dress"):
14
- """
15
- Generate an image using Hugging Face API with a specific style.
16
- """
17
- print(f"Generating {style} image with prompt:", prompt)
18
  api_url = f"https://api-inference.huggingface.co/models/{repo}"
19
- # token = os.getenv("API_TOKEN") # Uncomment and use your Hugging Face API token
20
  headers = {
21
- # "Authorization": f"Bearer {token}"
22
  }
23
- full_prompt = f"{prompt} {dress_trigger}" if style == "dress" else f"{prompt} {design_trigger}"
24
  payload = {
25
  "inputs": full_prompt,
26
  "parameters": {
@@ -38,7 +35,7 @@ def generate_image(prompt, style="dress"):
38
  print("API response status code:", response.status_code)
39
  if response.status_code == 200:
40
  print("Image generation successful!")
41
- return Image.open(BytesIO(response.content))
42
  elif response.status_code == 503:
43
  time.sleep(1)
44
  pbar.update(1)
@@ -49,67 +46,14 @@ def generate_image(prompt, style="dress"):
49
  print("API Error:", response.status_code)
50
  raise Exception(f"API Error: {response.status_code}")
51
 
52
- def blend_design(dress_img, design_img):
53
- """
54
- Blend the design image onto the dress image.
55
- """
56
- # Ensure both images are the same size
57
- dress_img = ImageOps.fit(dress_img, (512, 512))
58
- design_img = ImageOps.fit(design_img, (512, 512))
59
-
60
- # Create an alpha mask for blending
61
- design_mask = design_img.convert("L").point(lambda x: min(255, x * 2)) # Enhance design visibility
62
- blended = Image.composite(design_img, dress_img, design_mask)
63
-
64
- return blended
65
 
66
- # Define the interface for generating the minimalist dress
67
- def generate_minimalist_dress(dress_type_prompt, color_prompt):
68
- """
69
- Generate a minimalist dress based on type and color prompts.
70
- """
71
- prompt = f"{dress_type_prompt}, {color_prompt}"
72
- return generate_image(prompt, style="dress")
73
-
74
- # Define the interface for generating the design
75
- def generate_clothing_design(design_prompt):
76
- """
77
- Generate a design image based on the provided design prompt.
78
- """
79
- return generate_image(design_prompt, style="design")
80
-
81
- # Define the interface for blending the dress and design
82
- def blend_images(dress_image, design_image):
83
- """
84
- Blend a dress image and a design image together.
85
- """
86
- return blend_design(dress_image, design_image)
87
-
88
- # Gradio interface
89
- iface = gr.Blocks()
90
-
91
- with iface:
92
- gr.Markdown("# Minimalist Dress and Design Generator")
93
-
94
- with gr.Tab("Generate Minimalist Dress"):
95
- dress_type = gr.Textbox(label="Dress Type Prompt", placeholder="e.g., A-line dress, sleeveless dress")
96
- color = gr.Textbox(label="Color Prompt", placeholder="e.g., Red, pastel pink")
97
- dress_output = gr.Image(label="Generated Dress")
98
- dress_button = gr.Button("Generate Dress")
99
- dress_button.click(generate_minimalist_dress, inputs=[dress_type, color], outputs=dress_output)
100
-
101
- with gr.Tab("Generate Design"):
102
- design_prompt = gr.Textbox(label="Design Prompt", placeholder="e.g., Floral pattern, geometric design")
103
- design_output = gr.Image(label="Generated Design")
104
- design_button = gr.Button("Generate Design")
105
- design_button.click(generate_clothing_design, inputs=[design_prompt], outputs=design_output)
106
-
107
- with gr.Tab("Blend Dress and Design"):
108
- dress_input = gr.Image(type="pil", label="Upload Dress Image")
109
- design_input = gr.Image(type="pil", label="Upload Design Image")
110
- blended_output = gr.Image(label="Blended Output")
111
- blend_button = gr.Button("Blend Images")
112
- blend_button.click(blend_images, inputs=[dress_input, design_input], outputs=blended_output)
113
-
114
- # Launch interface
115
  iface.launch()
 
1
  import gradio as gr
2
  import requests
3
+ import os
4
+ 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 = "artificialguybr/TshirtDesignRedmond-V2"
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 = {
18
+ #"Authorization": f"Bearer {token}"
19
  }
20
+ full_prompt = f"{prompt} {trigger_word}"
21
  payload = {
22
  "inputs": full_prompt,
23
  "parameters": {
 
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)
 
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="Clothe Designs to use in our img2img model",
54
+ description="Make designs for your clothes",
55
+ examples=[["Cute Panda"], ["Skull"]]
56
+ )
 
 
 
 
 
57
 
58
+ print("Launching Gradio interface...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  iface.launch()