vhup 1.0__tar.gz → 1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vhup-1.0/vhup.egg-info → vhup-1.2}/PKG-INFO +1 -1
- {vhup-1.0 → vhup-1.2}/setup.py +1 -1
- vhup-1.2/vhup/__init__.py +2 -0
- vhup-1.2/vhup/horba.py +61 -0
- {vhup-1.0 → vhup-1.2/vhup.egg-info}/PKG-INFO +1 -1
- vhup-1.0/vhup/__init__.py +0 -2
- vhup-1.0/vhup/horba.py +0 -120
- {vhup-1.0 → vhup-1.2}/LICENSE +0 -0
- {vhup-1.0 → vhup-1.2}/README.md +0 -0
- {vhup-1.0 → vhup-1.2}/setup.cfg +0 -0
- {vhup-1.0 → vhup-1.2}/vhup/vhup.py +0 -0
- {vhup-1.0 → vhup-1.2}/vhup.egg-info/SOURCES.txt +0 -0
- {vhup-1.0 → vhup-1.2}/vhup.egg-info/dependency_links.txt +0 -0
- {vhup-1.0 → vhup-1.2}/vhup.egg-info/requires.txt +0 -0
- {vhup-1.0 → vhup-1.2}/vhup.egg-info/top_level.txt +0 -0
{vhup-1.0 → vhup-1.2}/setup.py
RENAMED
vhup-1.2/vhup/horba.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import cv2
|
|
3
|
+
import numpy as np
|
|
4
|
+
import os
|
|
5
|
+
from PIL import Image
|
|
6
|
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, DPMSolverMultistepScheduler
|
|
7
|
+
from deep_translator import GoogleTranslator
|
|
8
|
+
|
|
9
|
+
# Donanım ayarları
|
|
10
|
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
11
|
+
dtype = torch.float16 if device == "cuda" else torch.float32
|
|
12
|
+
|
|
13
|
+
# 1. ControlNet ve Model Yükleme
|
|
14
|
+
controlnet = ControlNetModel.from_pretrained(
|
|
15
|
+
"lllyasviel/sd-controlnet-canny",
|
|
16
|
+
torch_dtype=dtype
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
_pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
|
20
|
+
"runwayml/stable-diffusion-v1-5",
|
|
21
|
+
controlnet=controlnet,
|
|
22
|
+
torch_dtype=dtype,
|
|
23
|
+
safety_checker=None
|
|
24
|
+
).to(device)
|
|
25
|
+
|
|
26
|
+
_pipe.scheduler = DPMSolverMultistepScheduler.from_config(_pipe.scheduler.config)
|
|
27
|
+
translator = GoogleTranslator(source="tr", target="en")
|
|
28
|
+
|
|
29
|
+
def create_loop(prompt: str, foto: str) -> str:
|
|
30
|
+
# A. Referans Görsel İşleme (Canny Edge)
|
|
31
|
+
input_image = Image.open(foto).convert("RGB")
|
|
32
|
+
image_np = np.array(input_image)
|
|
33
|
+
|
|
34
|
+
# Kenar algılama ile iskelet çıkarma
|
|
35
|
+
image_canny = cv2.Canny(image_np, 100, 200)
|
|
36
|
+
image_canny = image_canny[:, :, None]
|
|
37
|
+
image_canny = np.concatenate([image_canny, image_canny, image_canny], axis=2)
|
|
38
|
+
canny_image = Image.fromarray(image_canny)
|
|
39
|
+
|
|
40
|
+
# B. Prompt Hazırlığı
|
|
41
|
+
# Türkçe giriş gelirse İngilizce'ye çevirir
|
|
42
|
+
translated_prompt = translator.translate(prompt)
|
|
43
|
+
|
|
44
|
+
# Kalite takıları (Quality Tags)
|
|
45
|
+
final_prompt = f"{translated_prompt}, highly detailed, masterpiece, 8k wallpaper"
|
|
46
|
+
negative_prompt = "lowres, bad anatomy, worst quality, blurry, deformed face"
|
|
47
|
+
|
|
48
|
+
# C. Üretim Süreci
|
|
49
|
+
output = _pipe(
|
|
50
|
+
prompt=final_prompt,
|
|
51
|
+
image=canny_image,
|
|
52
|
+
negative_prompt=negative_prompt,
|
|
53
|
+
num_inference_steps=30,
|
|
54
|
+
controlnet_conditioning_scale=0.7 # 0.7 referansa iyi sadık kalır ama yaratıcılığa da alan bırakır
|
|
55
|
+
).images[0]
|
|
56
|
+
|
|
57
|
+
# D. Kayıt
|
|
58
|
+
output_path = "vho_result.png"
|
|
59
|
+
output.save(output_path)
|
|
60
|
+
return os.path.abspath(output_path)
|
|
61
|
+
|
vhup-1.0/vhup/__init__.py
DELETED
vhup-1.0/vhup/horba.py
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import torch
|
|
2
|
-
import random
|
|
3
|
-
import os
|
|
4
|
-
from PIL import Image
|
|
5
|
-
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler
|
|
6
|
-
from transformers import CLIPVisionModelWithProjection, CLIPImageProcessor
|
|
7
|
-
from deep_translator import GoogleTranslator
|
|
8
|
-
|
|
9
|
-
# Cihaz ayarları
|
|
10
|
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
11
|
-
dtype = torch.float16 if device == "cuda" else torch.float32
|
|
12
|
-
|
|
13
|
-
FIXED_OUTPUT_FILE = "vho1.png"
|
|
14
|
-
translator = GoogleTranslator(source="tr", target="en")
|
|
15
|
-
|
|
16
|
-
TR_STYLE_MAP = {
|
|
17
|
-
"gerçekçi": "realistic", "sinematik": "cinematic lighting",
|
|
18
|
-
"anime": "anime style", "çizgi film": "cartoon style",
|
|
19
|
-
"karanlık": "dark dramatic mood", "neon": "neon cyberpunk lighting",
|
|
20
|
-
"portre": "portrait photography", "detaylı": "highly detailed",
|
|
21
|
-
"fantastik": "fantasy art", "bilim kurgu": "science fiction"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
def load_pipelines():
|
|
25
|
-
model_id = "runwayml/stable-diffusion-v1-5"
|
|
26
|
-
# Karakter koruma için kritik olan görsel işlemci
|
|
27
|
-
clip_id = "openai/clip-vit-large-patch14"
|
|
28
|
-
|
|
29
|
-
# 1. İşlemcileri yükle
|
|
30
|
-
img_proc = CLIPImageProcessor.from_pretrained(clip_id)
|
|
31
|
-
img_enc = CLIPVisionModelWithProjection.from_pretrained(
|
|
32
|
-
clip_id,
|
|
33
|
-
torch_dtype=dtype
|
|
34
|
-
).to(device)
|
|
35
|
-
|
|
36
|
-
# 2. Ana Pipeline'ı yükle
|
|
37
|
-
pipe = StableDiffusionPipeline.from_pretrained(
|
|
38
|
-
model_id,
|
|
39
|
-
image_encoder=img_enc,
|
|
40
|
-
torch_dtype=dtype,
|
|
41
|
-
safety_checker=None
|
|
42
|
-
).to(device)
|
|
43
|
-
|
|
44
|
-
# 3. IP-Adapter ağırlıklarını yükle
|
|
45
|
-
pipe.load_ip_adapter(
|
|
46
|
-
"h94/IP-Adapter",
|
|
47
|
-
subfolder="models",
|
|
48
|
-
weight_name="ip-adapter_sd15.bin"
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
pipe.set_ip_adapter_scale(0.7)
|
|
52
|
-
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
|
53
|
-
pipe.enable_attention_slicing()
|
|
54
|
-
|
|
55
|
-
# Kesin olarak 2 değer döndür
|
|
56
|
-
return pipe, img_proc
|
|
57
|
-
|
|
58
|
-
# Pipeline'ları başlat
|
|
59
|
-
_pipe, _image_processor = load_pipelines()
|
|
60
|
-
|
|
61
|
-
def _prepare_prompt(prompt_tr: str) -> str:
|
|
62
|
-
clean_prompt = prompt_tr.replace("#", "the person")
|
|
63
|
-
translated = translator.translate(clean_prompt)
|
|
64
|
-
styles = [en for tr, en in TR_STYLE_MAP.items() if tr in prompt_tr.lower()]
|
|
65
|
-
return f"{translated}, {', '.join(styles)}, masterpiece, high quality, sharp focus"
|
|
66
|
-
|
|
67
|
-
def _get_image_embeds(hero_path):
|
|
68
|
-
# Karakter görselini tensor formatına çevirir (Tuple hatasını önler)
|
|
69
|
-
face_img = Image.open(hero_path).convert("RGB")
|
|
70
|
-
clip_input = _image_processor(images=face_img, return_tensors="pt").to(device, dtype=dtype)
|
|
71
|
-
outputs = _pipe.image_encoder(**clip_input)
|
|
72
|
-
return outputs.image_embeds.unsqueeze(1)
|
|
73
|
-
|
|
74
|
-
def create_hore(prompt: str, hero: str, kalite: float = 7.5) -> str:
|
|
75
|
-
final_p = _prepare_prompt(prompt)
|
|
76
|
-
embeds = _get_image_embeds(hero)
|
|
77
|
-
|
|
78
|
-
seed = random.randint(0, 999999999)
|
|
79
|
-
gen = torch.Generator(device=device).manual_seed(seed)
|
|
80
|
-
|
|
81
|
-
image = _pipe(
|
|
82
|
-
prompt=final_p,
|
|
83
|
-
ip_adapter_image_embeds=[embeds],
|
|
84
|
-
negative_prompt="worst quality, low quality, bad anatomy, deformed",
|
|
85
|
-
num_inference_steps=30,
|
|
86
|
-
guidance_scale=kalite,
|
|
87
|
-
generator=gen
|
|
88
|
-
).images[0]
|
|
89
|
-
|
|
90
|
-
image.save(FIXED_OUTPUT_FILE)
|
|
91
|
-
return os.path.abspath(FIXED_OUTPUT_FILE)
|
|
92
|
-
|
|
93
|
-
def create_hore_Bef(prompt: str, hero: str, strength: float = 0.6) -> str:
|
|
94
|
-
# Önceki görsel yoksa create_hore'a pasla
|
|
95
|
-
if not os.path.exists(FIXED_OUTPUT_FILE):
|
|
96
|
-
return create_hore(prompt, hero)
|
|
97
|
-
|
|
98
|
-
current_bg = Image.open(FIXED_OUTPUT_FILE).convert("RGB")
|
|
99
|
-
embeds = _get_image_embeds(hero)
|
|
100
|
-
final_p = _prepare_prompt(prompt)
|
|
101
|
-
|
|
102
|
-
# Img2Img için geçici pipeline oluştur
|
|
103
|
-
i2i_pipe = StableDiffusionImg2ImgPipeline(**_pipe.components)
|
|
104
|
-
|
|
105
|
-
seed = random.randint(0, 999999999)
|
|
106
|
-
gen = torch.Generator(device=device).manual_seed(seed)
|
|
107
|
-
|
|
108
|
-
image = i2i_pipe(
|
|
109
|
-
prompt=final_p,
|
|
110
|
-
image=current_bg,
|
|
111
|
-
ip_adapter_image_embeds=[embeds],
|
|
112
|
-
strength=strength,
|
|
113
|
-
num_inference_steps=30,
|
|
114
|
-
negative_prompt="worst quality, low quality",
|
|
115
|
-
generator=gen
|
|
116
|
-
).images[0]
|
|
117
|
-
|
|
118
|
-
image.save(FIXED_OUTPUT_FILE)
|
|
119
|
-
return os.path.abspath(FIXED_OUTPUT_FILE)
|
|
120
|
-
|
{vhup-1.0 → vhup-1.2}/LICENSE
RENAMED
|
File without changes
|
{vhup-1.0 → vhup-1.2}/README.md
RENAMED
|
File without changes
|
{vhup-1.0 → vhup-1.2}/setup.cfg
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|