Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +11 -0
- .gitignore +6 -0
- README.md +3 -9
- app.py +415 -0
- data/01_original/gallery_images/0.png +0 -0
- data/01_original/gallery_images/00.png +3 -0
- data/01_original/gallery_images/000.png +3 -0
- data/01_original/gallery_images/000003.png +0 -0
- data/01_original/gallery_images/001.png +3 -0
- data/01_original/gallery_images/002.png +3 -0
- data/01_original/gallery_images/006.png +3 -0
- data/01_original/gallery_images/01.png +0 -0
- data/01_original/gallery_images/03.png +0 -0
- data/01_original/gallery_images/05.png +0 -0
- data/01_original/gallery_images/06.png +0 -0
- data/01_original/gallery_images/08.png +0 -0
- data/01_original/gallery_images/1.png +0 -0
- data/01_original/gallery_images/10.png +0 -0
- data/01_original/gallery_images/11.png +0 -0
- data/01_original/gallery_images/13.png +0 -0
- data/01_original/gallery_images/14.png +0 -0
- data/01_original/gallery_images/15.png +0 -0
- data/01_original/gallery_images/16.png +0 -0
- data/01_original/gallery_images/2.png +0 -0
- data/01_original/gallery_images/20.png +3 -0
- data/01_original/gallery_images/21.png +0 -0
- data/01_original/gallery_images/22.png +0 -0
- data/01_original/gallery_images/3.png +3 -0
- data/01_original/gallery_images/4.png +0 -0
- data/01_original/gallery_images/5.png +0 -0
- data/01_original/gallery_images/50.png +3 -0
- data/01_original/gallery_images/51.png +3 -0
- data/01_original/gallery_images/52.png +3 -0
- data/01_original/gallery_images/53.png +0 -0
- data/01_original/gallery_images/55.png +0 -0
- data/01_original/gallery_images/56.png +0 -0
- data/01_original/gallery_images/57.png +0 -0
- data/01_original/gallery_images/58.png +0 -0
- data/01_original/gallery_images/59.png +0 -0
- data/01_original/gallery_images/6.png +3 -0
- data/01_original/gallery_images/60.png +0 -0
- data/01_original/gallery_images/7.png +0 -0
- data/01_original/gallery_images/8.png +0 -0
- data/01_original/gallery_images/9.png +0 -0
- data/02_processed/car_image_file_name.csv +0 -0
- data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_closeup_shot_left_side_image.png +0 -0
- data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_closeup_shot_right_side_car_bottom_image.png +0 -0
- data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_closeup_shot_right_side_image.png +0 -0
- data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_normal_shot_image.png +0 -0
- data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_10_degree_closeup_shot_left_side_image.png +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,14 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
data/01_original/gallery_images/00.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
data/01_original/gallery_images/000.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
data/01_original/gallery_images/001.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
data/01_original/gallery_images/002.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
data/01_original/gallery_images/006.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
data/01_original/gallery_images/20.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
data/01_original/gallery_images/3.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
data/01_original/gallery_images/50.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
data/01_original/gallery_images/51.png filter=lfs diff=lfs merge=lfs -text
|
45 |
+
data/01_original/gallery_images/52.png filter=lfs diff=lfs merge=lfs -text
|
46 |
+
data/01_original/gallery_images/6.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/.env
|
2 |
+
/.venv
|
3 |
+
/.vscode
|
4 |
+
/01_image_download.ipynb
|
5 |
+
/02_preprocessing_code.ipynb
|
6 |
+
/03_hackathon_code.ipynb
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji: 🔥
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: blue
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.37.2
|
8 |
app_file: app.py
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: test
|
|
|
|
|
|
|
|
|
|
|
3 |
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 4.37.1
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import json
|
4 |
+
import cv2
|
5 |
+
import time
|
6 |
+
import requests
|
7 |
+
import numpy as np
|
8 |
+
import gradio as gr
|
9 |
+
import pandas as pd
|
10 |
+
from PIL import Image
|
11 |
+
from io import BytesIO
|
12 |
+
from openai import OpenAI
|
13 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
14 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
15 |
+
|
16 |
+
import warnings
|
17 |
+
warnings.filterwarnings("ignore")
|
18 |
+
|
19 |
+
|
20 |
+
client = OpenAI(api_key='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')
|
21 |
+
STABILITY_KEY = "sk-8Wcz3bcvHo4r0ehXEvcC2mQu4gV3aYWdrdFmtri9Isn1ycDp"
|
22 |
+
|
23 |
+
def send_generation_request(host,params,):
|
24 |
+
headers = {"Accept": "image/*","Authorization": f"Bearer {STABILITY_KEY}"}
|
25 |
+
|
26 |
+
# Encode parameters
|
27 |
+
files = {}
|
28 |
+
image = params.pop("image", None)
|
29 |
+
mask = params.pop("mask", None)
|
30 |
+
if image is not None and image != '':
|
31 |
+
files["image"] = open(image, 'rb')
|
32 |
+
if mask is not None and mask != '':
|
33 |
+
files["mask"] = open(mask, 'rb')
|
34 |
+
if len(files)==0:
|
35 |
+
files["none"] = ''
|
36 |
+
|
37 |
+
# Send request
|
38 |
+
print(f"Sending REST request to {host}...")
|
39 |
+
response = requests.post(
|
40 |
+
host,
|
41 |
+
headers=headers,
|
42 |
+
files=files,
|
43 |
+
data=params
|
44 |
+
)
|
45 |
+
if not response.ok:
|
46 |
+
raise Exception(f"HTTP {response.status_code}: {response.text}")
|
47 |
+
|
48 |
+
return response
|
49 |
+
|
50 |
+
def send_async_generation_request(
|
51 |
+
host,
|
52 |
+
params,
|
53 |
+
):
|
54 |
+
headers = {
|
55 |
+
"Accept": "application/json",
|
56 |
+
"Authorization": f"Bearer {STABILITY_KEY}"
|
57 |
+
}
|
58 |
+
|
59 |
+
# Encode parameters
|
60 |
+
files = {}
|
61 |
+
if "image" in params:
|
62 |
+
image = params.pop("image")
|
63 |
+
files = {"image": open(image, 'rb')}
|
64 |
+
|
65 |
+
# Send request
|
66 |
+
print(f"Sending REST request to {host}...")
|
67 |
+
response = requests.post(
|
68 |
+
host,
|
69 |
+
headers=headers,
|
70 |
+
files=files,
|
71 |
+
data=params
|
72 |
+
)
|
73 |
+
if not response.ok:
|
74 |
+
raise Exception(f"HTTP {response.status_code}: {response.text}")
|
75 |
+
|
76 |
+
# Process async response
|
77 |
+
response_dict = json.loads(response.text)
|
78 |
+
generation_id = response_dict.get("id", None)
|
79 |
+
assert generation_id is not None, "Expected id in response"
|
80 |
+
|
81 |
+
# Loop until result or timeout
|
82 |
+
timeout = int(os.getenv("WORKER_TIMEOUT", 500))
|
83 |
+
start = time.time()
|
84 |
+
status_code = 202
|
85 |
+
while status_code == 202:
|
86 |
+
response = requests.get(
|
87 |
+
f"{host}/result/{generation_id}",
|
88 |
+
headers={
|
89 |
+
**headers,
|
90 |
+
"Accept": "image/*"
|
91 |
+
},
|
92 |
+
)
|
93 |
+
|
94 |
+
if not response.ok:
|
95 |
+
raise Exception(f"HTTP {response.status_code}: {response.text}")
|
96 |
+
status_code = response.status_code
|
97 |
+
time.sleep(10)
|
98 |
+
if time.time() - start > timeout:
|
99 |
+
raise Exception(f"Timeout after {timeout} seconds")
|
100 |
+
|
101 |
+
return response
|
102 |
+
|
103 |
+
def bckgrnd_removal(Im):
|
104 |
+
image = str(Im)
|
105 |
+
output_format = "png"
|
106 |
+
host = f"https://api.stability.ai/v2beta/stable-image/edit/remove-background"
|
107 |
+
params = {"image" : image,"output_format": output_format}
|
108 |
+
response = send_generation_request(host,params)
|
109 |
+
|
110 |
+
# Decode response
|
111 |
+
output_image = response.content
|
112 |
+
finish_reason = response.headers.get("finish-reason")
|
113 |
+
seed = response.headers.get("seed")
|
114 |
+
|
115 |
+
# Check for NSFW classification
|
116 |
+
if finish_reason == 'CONTENT_FILTERED':
|
117 |
+
raise Warning("Generation failed NSFW classifier")
|
118 |
+
|
119 |
+
# Save and display result
|
120 |
+
filename, _ = os.path.splitext(os.path.basename(image))
|
121 |
+
bckgrnd_removed_image = f"data\\03_app_generated\\01_bckgrnd_removed_image_{filename}_{seed}.{output_format}"
|
122 |
+
with open(bckgrnd_removed_image, "wb") as f:
|
123 |
+
f.write(output_image)
|
124 |
+
return bckgrnd_removed_image
|
125 |
+
|
126 |
+
def custom_tokenizer(text):
|
127 |
+
# Using regular expressions to split and filter alphanumeric tokens
|
128 |
+
return [token for token in re.split('[ _]', text) if token.isalnum()]
|
129 |
+
|
130 |
+
def search_image(prmpt):
|
131 |
+
df = pd.read_csv("data\\02_processed\\car_image_file_name.csv")
|
132 |
+
filenames = df['Filename'].values
|
133 |
+
|
134 |
+
# Initialize the TfidfVectorizer with the custom tokenizer
|
135 |
+
vectorizer = TfidfVectorizer(tokenizer=custom_tokenizer)
|
136 |
+
X_filenames = vectorizer.fit_transform(filenames)
|
137 |
+
|
138 |
+
# Define a user query and vectorize it
|
139 |
+
user_query = prmpt
|
140 |
+
X_query = vectorizer.transform([user_query])
|
141 |
+
|
142 |
+
# Compute the cosine similarity scores
|
143 |
+
similarity_scores = cosine_similarity(X_query, X_filenames)
|
144 |
+
|
145 |
+
# Create a DataFrame with filenames and their similarity scores
|
146 |
+
results_df = pd.DataFrame({
|
147 |
+
'Filename': filenames,
|
148 |
+
'Similarity Score': similarity_scores.flatten() # ensure the similarity scores are in the correct shape
|
149 |
+
})
|
150 |
+
|
151 |
+
# Write the results to a CSV file
|
152 |
+
results_df.to_csv("data\\02_processed\\similarity_scores.csv", index=False)
|
153 |
+
|
154 |
+
sorted_results_df = results_df.sort_values(by='Similarity Score', ascending=False)
|
155 |
+
|
156 |
+
# Display the top 10 results
|
157 |
+
top_6_results = sorted_results_df.head(20)
|
158 |
+
top_6_results['Filename']= top_6_results['Filename'].apply(lambda x:"data\\02_processed\\cv_final_renamed_2\\"+x)
|
159 |
+
return top_6_results['Filename'].tolist()
|
160 |
+
|
161 |
+
|
162 |
+
def prmpt_enhancer(rd,prmpt):
|
163 |
+
gbf_ip_prmpt = f"Act as expert prompt engineer. I will provide you with a preliminary prompt to generate a background image for a car using inpainting. Step-by-step, identify and integrate unique architectural elements suitable for the setting to enhance its luxury—refer to the provided examples. In consultation with the art director, refine the background to harmonize with the car's color. Finally, enhance the prompt to ensure it incorporates aesthetically pleasing elements for image generation in Stable Diffusion.Write the final prompt in JSON format with the prompt key.##Prompt:```{prmpt}``` \n Examples:car before arab home : car with shadow infront of modern arab villa with perforated facade and trees, warm color, villa cover top of the image, hyperrealistic \n car infront of showroom : Car standing outside 8 Modern artisitic luxury car showroom made of glass with blue sk , highly detailed, warm tone , 8k resolution, hyperrealistic \n car inside showroom : car on Showroom Floor in luxury glass showroom with decorative screen, Vibrant, enticing, commercial, product-focused, eye-catching, professional, highly detailed, warm tone, hyperrealistic \n car on mountain: car with shadow on snow filled path himalayas, top of image is filled with blue sky and snowy mountain, hyperrealistic'\n car before repair center: car with shadow parked in front of a bustling car repair center with bold digital yellow shop hoarding and blue sky , midday, 8K resolution, hyperrealistic"
|
164 |
+
ip_ip_prmpt = f"Act as expert Prompt Engineer. You will be provided with a prompt. Your task is to infuse expressions to human prompt you receive. Only enhance the expression and dress style; do not add details about the car background or the car color. consult with art director and human behaviour analyst to revamp the prompt. \n Example Prompt ```A Arab Traditional family standing before car``` transformed to ```8k, Fashion portrait of a traditional Arab family stands proudly in front of their car, exuding a sense of joyful pride.``` Here are similar transformations and enhancements for other scenarios a. 8K, Fashion portrait of a girl jumping in excitement with a shopping bag; \n b.8K, Fashion portrait of two children dressed in sunflower yellow winter clothing, shivering from the cold as they stand next to their father, who is holding a snowboard, ready for a photo; \n c.8K, Fashion portrait of an excited young woman standing next to her car; \n d. 8K, Fashion portrait of a happy young Arab traditional family caresses the car, children jumping with joy; \n e. 8K, Fashion portrait of a happy young man reclining on a car with one leg on the car;\n f.8K, Fashion portrait of a joyful young man in a suit standing beside a woman in a golden dress. ##Prompt:```{prmpt}```\n Write the final prompt in JSON format with the prompt key."
|
165 |
+
|
166 |
+
if rd == 'Generative Background Fill':
|
167 |
+
completion = client.chat.completions.create(
|
168 |
+
model="gpt-4",
|
169 |
+
messages=[
|
170 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
171 |
+
{"role": "user", "content": gbf_ip_prmpt}
|
172 |
+
]
|
173 |
+
)
|
174 |
+
input_text = completion.choices[0].message.content
|
175 |
+
else:
|
176 |
+
completion = client.chat.completions.create(
|
177 |
+
model="gpt-4",
|
178 |
+
messages=[
|
179 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
180 |
+
{"role": "user", "content": ip_ip_prmpt}
|
181 |
+
]
|
182 |
+
)
|
183 |
+
input_text = completion.choices[0].message.content
|
184 |
+
|
185 |
+
json_match = re.search(r'```json\n({.*?})\n```', input_text, re.DOTALL)
|
186 |
+
|
187 |
+
# print(json_match)
|
188 |
+
|
189 |
+
if json_match:
|
190 |
+
json_str = json_match.group(1)
|
191 |
+
# print("----------")
|
192 |
+
# print(type(json_str))
|
193 |
+
json_data = json.loads(json_str)
|
194 |
+
# print("----------")
|
195 |
+
# print(type(json_data))
|
196 |
+
op_response = json_data["prompt"]
|
197 |
+
else:
|
198 |
+
op_response = "No JSON data found"
|
199 |
+
|
200 |
+
return op_response
|
201 |
+
|
202 |
+
|
203 |
+
def bckgrnd_gen(Im,bckgrnd_removal_prmpt,negative_prmpt,seed,output_format,ks):
|
204 |
+
image = cv2.imread(Im, cv2.IMREAD_UNCHANGED)
|
205 |
+
if image is not None:
|
206 |
+
print("Image loaded successfully!")
|
207 |
+
print("Shape of the image:", image.shape)
|
208 |
+
height, width, _ = image.shape
|
209 |
+
print(image.shape)
|
210 |
+
|
211 |
+
if image.shape[2] == 4:
|
212 |
+
alpha_channel = image[:, :, 3]
|
213 |
+
mask = alpha_channel == 0
|
214 |
+
mask = (mask * 255).astype(np.uint8)
|
215 |
+
|
216 |
+
kernel_size = int(ks)
|
217 |
+
kernel = np.ones((kernel_size, kernel_size), np.uint8)
|
218 |
+
dilated_mask = cv2.dilate(mask, kernel, iterations=7)
|
219 |
+
cv2.imwrite('data\\03_app_generated\\02_transparent_mask.png', dilated_mask)
|
220 |
+
|
221 |
+
white_background = np.ones((height, width, 3), dtype=np.uint8) * 255
|
222 |
+
alpha_channel = image[:, :, 3] / 255.0
|
223 |
+
alpha_layer = np.stack([alpha_channel]*3, axis=-1)
|
224 |
+
|
225 |
+
foreground = (image[:, :, :3] * alpha_layer).astype(np.uint8)
|
226 |
+
background = (white_background * (1 - alpha_layer)).astype(np.uint8)
|
227 |
+
blended_image = cv2.add(foreground, background)
|
228 |
+
cv2.imwrite('data\\03_app_generated\\02_blended_image.png', blended_image)
|
229 |
+
|
230 |
+
else:
|
231 |
+
# mask = np.all(image == [0, 0, 0], axis=-1)
|
232 |
+
# white_mask = np.where(mask[..., None], [255, 255, 255], [0, 0, 0])
|
233 |
+
# gray_image = cv2.cvtColor(white_mask.astype(np.uint8), cv2.COLOR_BGR2GRAY)
|
234 |
+
# cv2.imwrite('transparent_mask.png', gray_image)
|
235 |
+
|
236 |
+
# blended_image = cv2.imread(Im, cv2.IMREAD_UNCHANGED)
|
237 |
+
# cv2.imwrite('blended_image.png', blended_image)
|
238 |
+
print("No Alpha Layer")
|
239 |
+
|
240 |
+
image = Im
|
241 |
+
mask = "data\\03_app_generated\\02_transparent_mask.png"
|
242 |
+
prompt = bckgrnd_removal_prmpt
|
243 |
+
negative_prompt = negative_prmpt
|
244 |
+
seed = str(seed)
|
245 |
+
output_format = output_format
|
246 |
+
|
247 |
+
host = f"https://api.stability.ai/v2beta/stable-image/edit/inpaint"
|
248 |
+
|
249 |
+
params = {
|
250 |
+
"image" : image,
|
251 |
+
"mask" : mask,
|
252 |
+
"negative_prompt" : negative_prompt,
|
253 |
+
"seed" : seed,
|
254 |
+
"mode": "mask",
|
255 |
+
"output_format": output_format,
|
256 |
+
"prompt" : prompt
|
257 |
+
}
|
258 |
+
|
259 |
+
response = send_generation_request(
|
260 |
+
host,
|
261 |
+
params
|
262 |
+
)
|
263 |
+
|
264 |
+
# Decode response
|
265 |
+
output_image = response.content
|
266 |
+
finish_reason = response.headers.get("finish-reason")
|
267 |
+
seed = response.headers.get("seed")
|
268 |
+
|
269 |
+
# Check for NSFW classification
|
270 |
+
if finish_reason == 'CONTENT_FILTERED':
|
271 |
+
raise Warning("Generation failed NSFW classifier")
|
272 |
+
|
273 |
+
# Save and display result
|
274 |
+
filename, _ = os.path.splitext(os.path.basename(image))
|
275 |
+
edited = f"data\\03_app_generated\\BCG_{filename}_{seed}.{output_format}"
|
276 |
+
with open(edited, "wb") as f:
|
277 |
+
f.write(output_image)
|
278 |
+
|
279 |
+
return edited
|
280 |
+
|
281 |
+
|
282 |
+
def character_inpainting(Im,prmpt,negative_prmpt,seed,output_format):
|
283 |
+
Im["composite"].save('data\\03_app_generated\\composite_final.png')
|
284 |
+
Im["layers"][0] = Im["layers"][0].convert('L')
|
285 |
+
Im["layers"][0].save('data\\03_app_generated\\mask_final.png')
|
286 |
+
Im["composite"].save('data\\03_app_generated\\background_final.png')
|
287 |
+
|
288 |
+
mask_path = 'data\\03_app_generated\\mask_final.png'
|
289 |
+
with Image.open(mask_path) as mask:
|
290 |
+
gray_mask = mask.convert('L') # Convert to grayscale
|
291 |
+
gray_mask.save('data\\03_app_generated\\IP_mask_white.png')
|
292 |
+
|
293 |
+
image = 'data\\03_app_generated\\background_final.png'
|
294 |
+
mask = 'data\\03_app_generated\\IP_mask_white.png'
|
295 |
+
|
296 |
+
prompt = prmpt
|
297 |
+
negative_prompt = negative_prmpt
|
298 |
+
seed = int(seed)
|
299 |
+
output_format = output_format
|
300 |
+
|
301 |
+
host = f"https://api.stability.ai/v2beta/stable-image/edit/inpaint"
|
302 |
+
|
303 |
+
params = {
|
304 |
+
"image" : image,
|
305 |
+
"mask" : mask,
|
306 |
+
"negative_prompt" : negative_prompt,
|
307 |
+
"seed" : seed,
|
308 |
+
"mode": "mask",
|
309 |
+
"output_format": output_format,
|
310 |
+
"prompt" : prompt
|
311 |
+
}
|
312 |
+
|
313 |
+
response = send_generation_request(
|
314 |
+
host,
|
315 |
+
params
|
316 |
+
)
|
317 |
+
|
318 |
+
# Decode response
|
319 |
+
output_image = response.content
|
320 |
+
finish_reason = response.headers.get("finish-reason")
|
321 |
+
seed = response.headers.get("seed")
|
322 |
+
|
323 |
+
# Check for NSFW classification
|
324 |
+
if finish_reason == 'CONTENT_FILTERED':
|
325 |
+
raise Warning("Generation failed NSFW classifier")
|
326 |
+
|
327 |
+
# Save and display result
|
328 |
+
filename, _ = os.path.splitext(os.path.basename(image))
|
329 |
+
edited = f"edited_{filename}_{seed}.{output_format}"
|
330 |
+
|
331 |
+
with open(edited, "wb") as f:
|
332 |
+
f.write(output_image)
|
333 |
+
|
334 |
+
return edited
|
335 |
+
|
336 |
+
def list_folder_contents(folder_path):
|
337 |
+
gallery_path_list = []
|
338 |
+
# Walk through all directories and files in the folder
|
339 |
+
for root, dirs, files in os.walk(folder_path):
|
340 |
+
for name in files:
|
341 |
+
gallery_path_list.append(os.path.join(root, name))
|
342 |
+
for name in dirs:
|
343 |
+
gallery_path_list.append(os.path.join(root, name))
|
344 |
+
return gallery_path_list
|
345 |
+
|
346 |
+
# Example usage
|
347 |
+
folder_path = 'data\\01_original\\gallery_images\\'
|
348 |
+
folder_contents = list_folder_contents(folder_path)
|
349 |
+
#print(folder_contents)
|
350 |
+
|
351 |
+
|
352 |
+
|
353 |
+
with gr.Blocks() as demo:
|
354 |
+
gr.Markdown(
|
355 |
+
"""
|
356 |
+
# blend.ai (Fractal Hackathon)
|
357 |
+
# Team: Moonshot
|
358 |
+
Enhance your marketing visuals effortlessly with Blend.ai, our state-of-the-art inpainting tool designed for seamless image edits. Transform your images into captivating masterpieces with precision and ease!
|
359 |
+
""")
|
360 |
+
|
361 |
+
with gr.Tab("Background Remover"):
|
362 |
+
gr.Interface(
|
363 |
+
fn=bckgrnd_removal,
|
364 |
+
inputs=gr.Text(label="Image Path"),
|
365 |
+
outputs=gr.Image(format="png", show_download_button=True),
|
366 |
+
allow_flagging=False,
|
367 |
+
title="Background Remover",
|
368 |
+
description="Provide the path to a PNG image of your product. Our tool will automatically remove the background, making it perfect for professional presentations and marketing material."
|
369 |
+
)
|
370 |
+
|
371 |
+
with gr.Tab("Image Search"):
|
372 |
+
gr.Interface(
|
373 |
+
fn=search_image,
|
374 |
+
inputs=gr.Text(label="Prompt"),
|
375 |
+
outputs=gr.Gallery(),
|
376 |
+
allow_flagging=False,
|
377 |
+
title="Image Search",
|
378 |
+
description="Search and retrieve images based on your text prompts. Ideal for finding specific product shots or design inspirations. Example prompts are included for quick testing.",
|
379 |
+
examples=['toyota corolla blue cross 30 degree closeup shot', 'Toyota 2024 Land Cruiser 270 black degree normal shot', 'nissan two tone monarch orange left normal shot']
|
380 |
+
)
|
381 |
+
|
382 |
+
with gr.Tab("Prompt Enhancer"):
|
383 |
+
gr.Interface(
|
384 |
+
fn=prmpt_enhancer,
|
385 |
+
inputs=[gr.Radio(["Generative Background Fill", "Inpaint Characters"], label="Section", info="Select the section for which you need to enhance prompt"), gr.Text(label="Prompt")],
|
386 |
+
outputs=[gr.Text(label="Enhanced Prompt")],
|
387 |
+
allow_flagging='never',
|
388 |
+
title="Prompt Enhancer",
|
389 |
+
description="Enhance your prompts to improve clarity and specificity. Select the type of enhancement and enter your initial prompt."
|
390 |
+
)
|
391 |
+
|
392 |
+
with gr.Tab("Generative Background Fill"):
|
393 |
+
gr.Interface(
|
394 |
+
fn=bckgrnd_gen,
|
395 |
+
inputs=[gr.Text(label="Image Path"), gr.TextArea(label="Prompt"), gr.Text(label="Negative Prompt", value="noisy, blurry, unattractive, sloppy, unprofessional, low quality"), gr.Text(label="Seed", value="0"), gr.Text(label="Output Format", value='png'), gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Kernel Size", show_label=True, info="Adjust Kernel size")],
|
396 |
+
outputs=[gr.Image(format="png", show_download_button=True),gr.Image(format="png", show_download_button=True)],
|
397 |
+
allow_flagging='never',
|
398 |
+
title="Generative Background Fill",
|
399 |
+
description="Upload an RGBA PNG image to add a custom background. Provide a positive prompt for desired elements, a negative prompt to exclude elements, and customize the output with our sliders."
|
400 |
+
)
|
401 |
+
|
402 |
+
with gr.Tab("Inpaint Characters"):
|
403 |
+
gr.Interface(
|
404 |
+
fn=character_inpainting,
|
405 |
+
inputs=[gr.ImageMask(type='pil', brush=gr.Brush(colors=["#ffffff"], color_mode="fixed"),sources = 'upload'), gr.TextArea(label="Prompt"), gr.Text(label="Negative Prompt", value="noisy,blurry,unattractive,sloppy,unprofessional,2D,text logos,signatures,out of frame,jpeg artifacts,ugly,poorly drawn,extra limbs,extra hands,extra feet,backwards limbs,extra fingers,extra toes,unrealistic, incorrect, bad anatomy,cut off body pieces,strange body positions, impossible body positioning, Mismatched eyes, cross eyed, crooked face, crooked lips, unclear, undefined, mutations, deformities,off center,poor_composition, duplicate faces, plastic,fake,negativity,blurry,blurred,doll,unclear,bad anatomy,lowres,worstquality,watermark,bad proportions,long neck,deformed,mutated,mutation,disfigured,poorly drawn face,skin blemishes,skin spots,acnes,missing limb,malformed limbs,floating limbs,disconnected limbs,extra limb,extra arms,poorly drawn hands,malformed hands,mutated hands and fingers,bad hands,missing fingers,fused fingers,too many fingers,extra legs,bad feet,cross-eyed,low quality,bad-hands-5,BadNegAnatomyV1-neg,EasyNegative,FastNegativeV2,bad-picture-chill-75v"), gr.Text(label="Seed", value="0"), gr.Text(label="Output Format", value='png')],
|
406 |
+
outputs=["image",gr.Image(format="png", show_download_button=True)],
|
407 |
+
title="Inpaint Characters",
|
408 |
+
description="Start by uploading an image you've enhanced in the Generative Background Fill section. Use the masking tool to designate the specific area where you wish to add new characters or elements. Then, provide a detailed prompt for the inpainting process. This tool is designed to seamlessly blend new components into your existing image, significantly enriching its visual narrative and overall aesthetic appeal. It's ideal for creating compelling scenes or adding intricate details that align with your creative vision.",
|
409 |
+
allow_flagging='never'
|
410 |
+
)
|
411 |
+
|
412 |
+
with gr.Tab("Gallery"):
|
413 |
+
gr.Gallery(value=folder_contents, columns=[4], rows=[10], object_fit="contain", height="auto")
|
414 |
+
|
415 |
+
demo.launch(share=True)
|
data/01_original/gallery_images/0.png
ADDED
![]() |
data/01_original/gallery_images/00.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/000.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/000003.png
ADDED
![]() |
data/01_original/gallery_images/001.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/002.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/006.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/01.png
ADDED
![]() |
data/01_original/gallery_images/03.png
ADDED
![]() |
data/01_original/gallery_images/05.png
ADDED
![]() |
data/01_original/gallery_images/06.png
ADDED
![]() |
data/01_original/gallery_images/08.png
ADDED
![]() |
data/01_original/gallery_images/1.png
ADDED
![]() |
data/01_original/gallery_images/10.png
ADDED
![]() |
data/01_original/gallery_images/11.png
ADDED
![]() |
data/01_original/gallery_images/13.png
ADDED
![]() |
data/01_original/gallery_images/14.png
ADDED
![]() |
data/01_original/gallery_images/15.png
ADDED
![]() |
data/01_original/gallery_images/16.png
ADDED
![]() |
data/01_original/gallery_images/2.png
ADDED
![]() |
data/01_original/gallery_images/20.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/21.png
ADDED
![]() |
data/01_original/gallery_images/22.png
ADDED
![]() |
data/01_original/gallery_images/3.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/4.png
ADDED
![]() |
data/01_original/gallery_images/5.png
ADDED
![]() |
data/01_original/gallery_images/50.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/51.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/52.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/53.png
ADDED
![]() |
data/01_original/gallery_images/55.png
ADDED
![]() |
data/01_original/gallery_images/56.png
ADDED
![]() |
data/01_original/gallery_images/57.png
ADDED
![]() |
data/01_original/gallery_images/58.png
ADDED
![]() |
data/01_original/gallery_images/59.png
ADDED
![]() |
data/01_original/gallery_images/6.png
ADDED
![]() |
Git LFS Details
|
data/01_original/gallery_images/60.png
ADDED
![]() |
data/01_original/gallery_images/7.png
ADDED
![]() |
data/01_original/gallery_images/8.png
ADDED
![]() |
data/01_original/gallery_images/9.png
ADDED
![]() |
data/02_processed/car_image_file_name.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_closeup_shot_left_side_image.png
ADDED
![]() |
data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_closeup_shot_right_side_car_bottom_image.png
ADDED
![]() |
data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_closeup_shot_right_side_image.png
ADDED
![]() |
data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_100_degree_normal_shot_image.png
ADDED
![]() |
data/02_processed/cv_final_renamed_2/Nissan_kicks_2024_SR_boulder_gray_pearl_gray_10_degree_closeup_shot_left_side_image.png
ADDED
![]() |