SIUBIU commited on
Commit
990203a
·
verified ·
1 Parent(s): f9a55c7

Upload prompt_gen.py

Browse files
Files changed (1) hide show
  1. prompt_gen.py +38 -0
prompt_gen.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import os
3
+ from openai import OpenAI
4
+
5
+ nv_prompt_file = pd.read_excel('汉服-女词库.xlsx')
6
+ na_prompt_file = pd.read_excel('汉服-男词库.xlsx')
7
+ nv_prompt = nv_prompt_file.to_string(index=False)
8
+ na_prompt = na_prompt_file.to_string(index=False)
9
+
10
+ os.environ["OPENAI_API_KEY"] = "sk-vtyR3fdgk08jmJ5e3eF6F5Ef663c4a3bAd0166C3549a1a8e"
11
+ os.environ["OPENAI_BASE_URL"] = "http://15.204.101.64:4000/v1"
12
+
13
+
14
+ def prompt_gen(advise, gender):
15
+ if gender == "男":
16
+ prompt = na_prompt
17
+ trigger = "A Hanfu"
18
+ else:
19
+ prompt = nv_prompt
20
+ trigger = "a Hanfu"
21
+
22
+ client = OpenAI()
23
+ completion = client.chat.completions.create(
24
+ model="gpt-4o",
25
+ messages=[
26
+ {"role": "system",
27
+ "content": "You are a helpful assistant.",},
28
+ {"role": "user",
29
+ "content": advise + "根据建议,从以下的触发词、种类、上衣、裙子、领子、袖子、袖口、腰饰、裙子详述中每个挑选一个词,分点描述,触发词固定选择为" + trigger +
30
+ ", 把英文也附在后面的括号里,然后在下面先加一条prompt,标题为‘# prompt’,并在此标题下总结所有英文描述,用逗"
31
+ "号间隔,再加上‘, (white background)’, 然后换行后以'promptEnd'结尾;再然后加一条服饰风格介绍,标题为"
32
+ "‘# 服饰风格介绍’,并在此标题下以介绍的口吻总结所有的中文描述。" + prompt,
33
+ }
34
+ ]
35
+
36
+ )
37
+ print(completion.choices[0].message.content)
38
+ return completion.choices[0].message.content