Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
from huggingface_hub import login
|
| 3 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 4 |
from PIL import Image
|
| 5 |
-
import
|
| 6 |
|
| 7 |
|
| 8 |
|
|
@@ -31,11 +31,13 @@ model.to(device)
|
|
| 31 |
@spaces.GPU(duration=300)
|
| 32 |
def generate_caption_and_image(image):
|
| 33 |
img = image.convert("RGB")
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
|
@@ -44,7 +46,7 @@ def generate_caption_and_image(image):
|
|
| 44 |
inputs = {key: val.to(device) for key, val in inputs.items()}
|
| 45 |
out = model.generate(**inputs)
|
| 46 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 47 |
-
prompt = f"Create a highly realistic design of a clothing item based on the following description: 'The design should incorporate elements from the extracted text: {
|
| 48 |
|
| 49 |
|
| 50 |
# Generate image based on the caption
|
|
|
|
| 2 |
from huggingface_hub import login
|
| 3 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 4 |
from PIL import Image
|
| 5 |
+
import easyocr
|
| 6 |
|
| 7 |
|
| 8 |
|
|
|
|
| 31 |
@spaces.GPU(duration=300)
|
| 32 |
def generate_caption_and_image(image):
|
| 33 |
img = image.convert("RGB")
|
| 34 |
+
reader = easyocr.Reader(['en'])
|
| 35 |
+
result = reader.readtext(img)
|
| 36 |
|
| 37 |
+
# Print the extracted text
|
| 38 |
+
for detection in result:
|
| 39 |
+
print(f"Detected text: {detection[1]}")
|
| 40 |
+
|
| 41 |
|
| 42 |
|
| 43 |
|
|
|
|
| 46 |
inputs = {key: val.to(device) for key, val in inputs.items()}
|
| 47 |
out = model.generate(**inputs)
|
| 48 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 49 |
+
prompt = f"Create a highly realistic design of a clothing item based on the following description: 'The design should incorporate elements from the extracted text: {result}, along with the caption: {caption}. The clothing should look realistic, modern, and stylish. Use high-quality fabric textures and realistic lighting to give the design a lifelike appearance. The colors, patterns, and materials should reflect the essence of the caption and extracted text.'"
|
| 50 |
|
| 51 |
|
| 52 |
# Generate image based on the caption
|