|
|
|
|
|
|
|
|
|
import os |
|
from tqdm import tqdm |
|
from gradio_client import Client, handle_file |
|
from PIL import Image |
|
from shutil import copy2 |
|
|
|
|
|
client = Client("http://localhost:7860") |
|
|
|
|
|
input_dir = "genshin_impact_ALBEDO_images_and_texts" |
|
output_dir = "genshin_impact_ALBEDO_oil_painting_and_texts" |
|
|
|
|
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
|
|
png_files = [f for f in os.listdir(input_dir) if f.endswith('.png')] |
|
|
|
|
|
for png_file in tqdm(png_files, desc="Processing images"): |
|
|
|
base_name = os.path.splitext(png_file)[0] |
|
txt_file = base_name + ".txt" |
|
|
|
|
|
txt_path = os.path.join(input_dir, txt_file) |
|
if not os.path.exists(txt_path): |
|
print(f"Warning: No corresponding .txt file found for {png_file}") |
|
continue |
|
|
|
|
|
with open(txt_path, 'r', encoding='utf-8') as f: |
|
prompt = f.read() |
|
|
|
|
|
|
|
|
|
prompt = ",".join(["In this realistic personal drawing"] + prompt.split(",")[1:]) |
|
|
|
|
|
result = client.predict( |
|
input_image=handle_file(os.path.join(input_dir, png_file)), |
|
prompt=prompt, |
|
negative_prompt="blurry, ugly, duplicate, poorly drawn, deformed, mosaic", |
|
seed=2718545171199645000, |
|
guidance_scale=8.5, |
|
scale=2, |
|
controlnet_conditioning_scale=0.5, |
|
strength=1, |
|
controlnet_start=0, |
|
controlnet_end=1, |
|
guassian_sigma=2, |
|
intensity_threshold=3, |
|
api_name="/predict" |
|
) |
|
|
|
|
|
generated_image_path = result[-1][1] |
|
|
|
|
|
output_image_path = os.path.join(output_dir, png_file) |
|
with Image.open(generated_image_path) as img: |
|
img.save(output_image_path) |
|
|
|
|
|
output_txt_path = os.path.join(output_dir, txt_file) |
|
with open(output_txt_path, 'w', encoding='utf-8') as f: |
|
f.write(prompt) |
|
|
|
print("Processing completed!") |
|
|