svjack commited on
Commit
34816fc
·
verified ·
1 Parent(s): ba05ee6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -23,7 +23,7 @@ def generate_prompts(user_input, csv_prompts, prefix, num_examples=3, language='
23
  system_prompt = (
24
  f"你是一位自然诗人,请将以下内容转化为{'英文' if language == 'English' else '中文'}的风景描写。"
25
  "请确保风格与提供的 CSV 中的描述一致,并以统一前缀 '{prefix}' 开头。"
26
- "请生成 {num_examples} 条不同风格的结果,每条结果应独立成段。"
27
  )
28
 
29
  # 拼接用户输入和 CSV 内容
@@ -43,14 +43,22 @@ def generate_prompts(user_input, csv_prompts, prefix, num_examples=3, language='
43
  raw_output = response.choices[0].message.content.strip()
44
  prompts = [line.strip() for line in raw_output.split('\n') if line.strip()]
45
 
46
- # 取前 num_examples 个有效结果
47
  prompts = prompts[:num_examples]
48
 
49
- # 处理后文本:每行以指定前缀开头
50
- processed_prompts = [f"{prefix} {p}" if not p.startswith(prefix) else p for p in prompts]
 
 
 
 
 
 
 
 
51
  processed_text = "\n".join(processed_prompts)
52
 
53
- return "\n\n".join(prompts), processed_text
54
 
55
  # Gradio 界面定义
56
  with gr.Blocks(title="提示词生成器", theme=gr.themes.Soft()) as app:
 
23
  system_prompt = (
24
  f"你是一位自然诗人,请将以下内容转化为{'英文' if language == 'English' else '中文'}的风景描写。"
25
  "请确保风格与提供的 CSV 中的描述一致,并以统一前缀 '{prefix}' 开头。"
26
+ "请生成 {num_examples} 条不同风格的结果,每条结果不要加编号,且保持简洁自然。"
27
  )
28
 
29
  # 拼接用户输入和 CSV 内容
 
43
  raw_output = response.choices[0].message.content.strip()
44
  prompts = [line.strip() for line in raw_output.split('\n') if line.strip()]
45
 
46
+ # 限制数量
47
  prompts = prompts[:num_examples]
48
 
49
+ # 处理后文本:每行以指定前缀开头(先判断是否已包含)
50
+ processed_prompts = []
51
+ for p in prompts:
52
+ if prefix not in p:
53
+ processed_prompts.append(f"{prefix} {p}")
54
+ else:
55
+ processed_prompts.append(p)
56
+
57
+ # 输出格式
58
+ output_text = "\n\n".join(prompts)
59
  processed_text = "\n".join(processed_prompts)
60
 
61
+ return output_text, processed_text
62
 
63
  # Gradio 界面定义
64
  with gr.Blocks(title="提示词生成器", theme=gr.themes.Soft()) as app: