Update app.py
Browse files
app.py
CHANGED
@@ -52,45 +52,46 @@ pipe.to(device)
|
|
52 |
|
53 |
@spaces.GPU(duration=150)
|
54 |
def generate_caption_and_image(image, f, p, d):
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
text = "a picture of "
|
68 |
-
inputs = processor(img, text, return_tensors="pt").to(device)
|
69 |
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
|
74 |
-
caption2 = processor.decode(out[0], skip_special_tokens=True)
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
# Generate image based on the caption
|
91 |
-
generated_image = pipe(prompt).images[0]
|
92 |
-
|
93 |
-
return prompt, generated_image
|
94 |
|
95 |
# Gradio UI
|
96 |
iface = gr.Interface(
|
|
|
52 |
|
53 |
@spaces.GPU(duration=150)
|
54 |
def generate_caption_and_image(image, f, p, d):
|
55 |
+
if f and p and d:
|
56 |
+
img = image.convert("RGB")
|
57 |
+
# reader = easyocr.Reader(['en'])
|
58 |
+
# # result = reader.readtext(img)
|
59 |
+
import random
|
60 |
+
|
61 |
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
text = "a picture of "
|
69 |
+
inputs = processor(img, text, return_tensors="pt").to(device)
|
70 |
+
|
71 |
+
out = model2.generate(**inputs, num_beams = 3)
|
72 |
+
|
73 |
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
caption2 = processor.decode(out[0], skip_special_tokens=True)
|
76 |
+
|
77 |
+
# Generate caption
|
78 |
+
inputs = processor(image, return_tensors="pt", padding=True, truncation=True, max_length=250)
|
79 |
+
inputs = {key: val.to(device) for key, val in inputs.items()}
|
80 |
+
out = model.generate(**inputs)
|
81 |
+
caption1 = processor.decode(out[0], skip_special_tokens=True)
|
82 |
|
83 |
+
prompt = f"Generate a clothing item using the following details: 1. {caption1} 2. {caption2} 3. Fabric: {f} 4. Pattern: {p} 5. Design Style: {d}. "
|
|
|
84 |
|
85 |
+
|
86 |
+
prompt +="The image should have a clean, minimalistic grey or white background, with realistic lighting and fine details, ensuring a sophisticated and polished appearance"
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
# Generate image based on the caption
|
92 |
+
generated_image = pipe(prompt).images[0]
|
93 |
+
|
94 |
+
return prompt, generated_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# Gradio UI
|
97 |
iface = gr.Interface(
|