SIUBIU commited on
Commit
f1de67e
·
verified ·
1 Parent(s): bb9f78b

Upload clothGen.py

Browse files
Files changed (1) hide show
  1. clothGen.py +77 -0
clothGen.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fal_client
2
+ import pandas as pd
3
+ from prompt_gen import prompt_gen
4
+ import requests
5
+ import os
6
+
7
+ nv_prompt_file = pd.read_excel('汉服-女词库.xlsx')
8
+ na_prompt_file = pd.read_excel('汉服-男词库.xlsx')
9
+ nv_prompt = nv_prompt_file.to_string(index=False)
10
+ na_prompt = na_prompt_file.to_string(index=False)
11
+
12
+
13
+ def cloth_gen(advice, gender):
14
+ lora_path = "https://huggingface.co/PPSharks/PPSharksModels/resolve/main/NV.safetensors"
15
+ if gender == "男":
16
+ lora_path = "https://huggingface.co/PPSharks/PPSharksModels/resolve/main/NA.safetensors"
17
+ else:
18
+ lora_path = "https://huggingface.co/PPSharks/PPSharksModels/resolve/main/NV.safetensors"
19
+
20
+ prompt = prompt_gen(advice, gender)
21
+ start_index = prompt.find("prompt" or "Prompt")
22
+ intro_index = prompt.find("服饰风格介绍")
23
+ cloth_intro = ""
24
+ promptGen = ""
25
+ if start_index != -1:
26
+ start_index += len("prompt\n\n")
27
+ end_index = prompt.find("promptEnd")
28
+ if end_index != -1:
29
+ extracted_content = prompt[start_index:end_index]
30
+ promptGen = extracted_content
31
+ print(extracted_content)
32
+ else:
33
+ print("No 'promptEnd' found after 'prompt'.")
34
+ else:
35
+ print("No 'prompt' found in the text.")
36
+ if intro_index != -1:
37
+ intro_index += len("服饰风格介绍\n\n")
38
+ cloth_intro = ("汉服,是汉民族的传统服饰。又称衣冠、衣裳、汉装。汉服是中国“衣冠上国”“礼仪之邦”“锦绣中华”的体现,承载了中国的染织绣等杰出"
39
+ "工艺和美学,传承了30多项中国非物质文化遗产以及受保护的中国工艺美术。\n") + prompt[intro_index:]
40
+ print(cloth_intro)
41
+ else:
42
+ print("No '服饰风格介绍' found.")
43
+
44
+ handler = fal_client.submit(
45
+ "fal-ai/fast-sdxl",
46
+ arguments={
47
+ "prompt": promptGen,
48
+ "negative_prompt": "human, people, person, man, woman, child, model, face, head, eyes, hands, arms, legs, "
49
+ "feet, hair, portrait, worst quality, low quality, normal quality, lowres, signature, "
50
+ "watermark, jpeg artifacts, logo, monochrome, grayscale, ugly",
51
+ "image_size": "portrait_4_3",
52
+ "num_inference_steps": 28,
53
+ "guidance_scale": 7.5,
54
+ "num_images": 6,
55
+ "loras": [{"path": lora_path, "scale": 0.7}],
56
+ "embeddings": [],
57
+ "safety_checker_version": "v1",
58
+ "format": "jpeg"
59
+ },
60
+ )
61
+
62
+ request_id = handler.request_id
63
+ result = fal_client.result("fal-ai/fast-sdxl", request_id)
64
+ cloth_image = []
65
+ save_directory = "downloads"
66
+ image_index = 1
67
+ for image in result['images']:
68
+ response = requests.get(image['url'])
69
+ if response.status_code == 200:
70
+ filename = os.path.join(save_directory, f"gen_cloth_{image_index}.jpeg")
71
+ cloth_image.append(filename)
72
+ with open(filename, 'wb') as f:
73
+ f.write(response.content)
74
+ image_index += 1
75
+ else:
76
+ print(f"Failed to download image from {image['url']}")
77
+ return cloth_image, cloth_image[0], cloth_intro