Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
index.py
CHANGED
|
@@ -13,9 +13,29 @@ from dotenv import load_dotenv, find_dotenv
|
|
| 13 |
# Locate the .env file
|
| 14 |
dotenv_path = find_dotenv()
|
| 15 |
load_dotenv(dotenv_path)
|
| 16 |
-
|
| 17 |
REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def generate_pattern(image, prompt):
|
| 20 |
|
| 21 |
if image is not None:
|
|
@@ -36,17 +56,16 @@ def generate_pattern(image, prompt):
|
|
| 36 |
|
| 37 |
# Resize the image
|
| 38 |
starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
transformed_image_pil = ImageChops.offset(starter_image_pil, horizontal_shift, vertical_shift)
|
| 47 |
-
else:
|
| 48 |
-
raise gr.Error(f"Please upload an image")
|
| 49 |
|
|
|
|
| 50 |
|
| 51 |
# Create a new image with black background and white cross
|
| 52 |
cross_image_pil = Image.new('RGB', (width, height), 'black')
|
|
|
|
| 13 |
# Locate the .env file
|
| 14 |
dotenv_path = find_dotenv()
|
| 15 |
load_dotenv(dotenv_path)
|
|
|
|
| 16 |
REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
|
| 17 |
|
| 18 |
+
def generate_sd3_image(prompt):
|
| 19 |
+
prompt = "texture sample zoomed in of " + prompt + ", perfect"
|
| 20 |
+
|
| 21 |
+
output = replicate.run(
|
| 22 |
+
"stability-ai/stable-diffusion-3",
|
| 23 |
+
input={
|
| 24 |
+
"cfg": 3.5,
|
| 25 |
+
"steps": 28,
|
| 26 |
+
"prompt": prompt,
|
| 27 |
+
"aspect_ratio": "1:1",
|
| 28 |
+
"output_format": "jpg",
|
| 29 |
+
"output_quality": 80,
|
| 30 |
+
"negative_prompt": "",
|
| 31 |
+
"prompt_strength": 0.85
|
| 32 |
+
}
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
response = requests.get(output[0])
|
| 36 |
+
|
| 37 |
+
return Image.open(io.BytesIO(response.content))
|
| 38 |
+
|
| 39 |
def generate_pattern(image, prompt):
|
| 40 |
|
| 41 |
if image is not None:
|
|
|
|
| 56 |
|
| 57 |
# Resize the image
|
| 58 |
starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
|
| 59 |
+
else:
|
| 60 |
+
starter_image_pil = generate_sd3_image(prompt)
|
| 61 |
|
| 62 |
|
| 63 |
+
# Move the image horizontally and vertically by 50%
|
| 64 |
+
width, height = starter_image_pil.size
|
| 65 |
+
horizontal_shift = width // 2
|
| 66 |
+
vertical_shift = height // 2
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
transformed_image_pil = ImageChops.offset(starter_image_pil, horizontal_shift, vertical_shift)
|
| 69 |
|
| 70 |
# Create a new image with black background and white cross
|
| 71 |
cross_image_pil = Image.new('RGB', (width, height), 'black')
|