Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
4 |
from PIL import Image
|
5 |
import easyocr
|
6 |
|
|
|
|
|
7 |
|
8 |
|
9 |
# Get Hugging Face Token from environment variable
|
@@ -15,6 +17,9 @@ login(token=hf_token)
|
|
15 |
# Load the processor and model
|
16 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
17 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
|
|
|
|
|
|
18 |
import gradio as gr
|
19 |
from diffusers import DiffusionPipeline
|
20 |
import torch
|
@@ -24,6 +29,7 @@ import spaces # Hugging Face Spaces module
|
|
24 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium")
|
25 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
26 |
pipe.to(device)
|
|
|
27 |
model.to(device)
|
28 |
|
29 |
|
@@ -55,7 +61,8 @@ def generate_caption_and_image(image):
|
|
55 |
inputs = {key: val.to(device) for key, val in inputs.items()}
|
56 |
out = model.generate(**inputs)
|
57 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
58 |
-
|
|
|
59 |
|
60 |
|
61 |
|
|
|
4 |
from PIL import Image
|
5 |
import easyocr
|
6 |
|
7 |
+
from transformers import pipeline
|
8 |
+
|
9 |
|
10 |
|
11 |
# Get Hugging Face Token from environment variable
|
|
|
17 |
# Load the processor and model
|
18 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
19 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
20 |
+
|
21 |
+
|
22 |
+
pipe2= pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
23 |
import gradio as gr
|
24 |
from diffusers import DiffusionPipeline
|
25 |
import torch
|
|
|
29 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium")
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
pipe.to(device)
|
32 |
+
pipe2.to(device)
|
33 |
model.to(device)
|
34 |
|
35 |
|
|
|
61 |
inputs = {key: val.to(device) for key, val in inputs.items()}
|
62 |
out = model.generate(**inputs)
|
63 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
64 |
+
caption2 =pipe2(img)
|
65 |
+
prompt = '''f'''Create a highly realistic clothing item based on the following descriptions: The design should reflect {caption1} and {caption2}, blending both themes into a single, stylish, and modern piece of clothing. Incorporate highly realistic and high-quality textures that exude sophistication, with realistic fabric lighting and fine details. Subtly hint at {selected_fabric}, featuring a {selected_pattern} motif and a {selected_textile_design} style that harmoniously balances the essence of both captions.''''''
|
66 |
|
67 |
|
68 |
|