sofiamak commited on
Commit
a51edd1
·
verified ·
1 Parent(s): 168b2d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -6,27 +6,26 @@ API_KEY = os.getenv("OPENAI_API_KEY")
6
  MODEL_NAME = "gpt-4o-mini"
7
  client = OpenAI(api_key=API_KEY)
8
 
9
- # —— 强化“灵感优先、创作度高”的系统提示 —— #
10
- SYSTEM_PROMPT = """You are a high-creativity pet name generator.
11
- Goal: Produce EXACTLY ONE pet name + one short quote line.
12
 
13
  Creative balance:
14
- - Inspiration source drives the concept (~70%).
15
  - User inputs (species / appearance / personality / gender) refine the vibe (~30%).
16
- - Keep outputs fresh and imaginative; avoid being too literal to user traits.
17
 
18
  NAME rules:
19
- - Prefer 2–3 syllables (or compact in Chinese), pleasant to pronounce.
20
- - Output in requested language (Chinese/English/Japanese/Korean/French).
21
- - You MAY echo famous/mythic names if truly fitting, but PREFER fresh coinages,
22
- playful twists, or affectionate diminutives in the chosen theme.
23
- - Provide ONE short meaning/explanation (≤12 words), themed first, traits second.
24
- - No numbers, no long descriptive phrases.
25
 
26
  QUOTE rules:
27
- - After the name line, provide ONE short quote about this animal type or spirit.
28
- - If a reliable real quote is recalled, include author; otherwise write a brief thematic aphorism and attribute as “Unknown” (or “Proverb”).
29
- - Keep quote language the same as requested language.
 
30
 
31
  STRICT OUTPUT: exactly two lines
32
  Name — short meaning
@@ -34,20 +33,18 @@ Quote: “...” — Attribution
34
  """
35
 
36
  def build_prompt(species, look, personality, gender, language, inspiration):
37
- # 允许用户特征为空;强调主题先行
38
  return f"""
39
  Requested language: {language}
40
  Inspiration source (primary): {inspiration}
41
- Refinement inputs (secondary, may be empty):
42
  - Species: {species or '(unspecified)'}
43
  - Appearance: {look or '(unspecified)'}
44
  - Personality: {personality or '(unspecified)'}
45
  - Gender: {gender}
46
 
47
  Task:
48
- 1) Create EXACTLY ONE pet name led by the inspiration source (~70%), with a short meaning (≤12 words).
49
- 2) Then output ONE quote line about this kind of animal/spirit (same language).
50
- Remember: be imaginative; do NOT overfit to the traits.
51
  """
52
 
53
  def generate_name(species, look, personality, gender, language, inspiration):
@@ -60,9 +57,9 @@ def generate_name(species, look, personality, gender, language, inspiration):
60
  )
61
  resp = client.chat.completions.create(
62
  model=MODEL_NAME,
63
- temperature=0.95, # 提高创造力
64
  top_p=0.95,
65
- max_tokens=260,
66
  messages=[
67
  {"role": "system", "content": SYSTEM_PROMPT},
68
  {"role": "user", "content": prompt}
@@ -72,8 +69,9 @@ def generate_name(species, look, personality, gender, language, inspiration):
72
  except Exception as e:
73
  return f"⚠️ 出错:{html.escape(str(e))}"
74
 
 
75
  with gr.Blocks(title="Pawfect Match") as demo:
76
- gr.Markdown("## 🐾 Pawfect Match|宠物起名机\n灵感优先(70%)+ 用户特征(30%)→ 一个名字 + 一句名言。")
77
 
78
  species = gr.Textbox(label="宠物种类", placeholder="例:金毛 / 英短 / 仓鼠 / 鹦鹉(可留空)")
79
  look = gr.Textbox(label="外表特征", placeholder="例:橘色短毛,大眼睛,白爪(可留空)")
 
6
  MODEL_NAME = "gpt-4o-mini"
7
  client = OpenAI(api_key=API_KEY)
8
 
9
+ # --- 系统提示,强化“可爱名字 + 真实温馨名言” ---
10
+ SYSTEM_PROMPT = """You are a playful yet creative pet name generator.
11
+ Goal: Produce EXACTLY ONE cute, pet-friendly name + one authentic quote line.
12
 
13
  Creative balance:
14
+ - Inspiration source (山海经 / 迪士尼 / 哈利波特 / 生活) drives the theme (~70%).
15
  - User inputs (species / appearance / personality / gender) refine the vibe (~30%).
 
16
 
17
  NAME rules:
18
+ - Must feel CUTE and easy to call out loud (pet style).
19
+ - Prefer 2–3 syllables; round and soft sounds are good.
20
+ - Draw imagery from the inspiration source, but keep tone playful and adorable.
21
+ - Output in the requested language (Chinese/English/Japanese/Korean/French).
22
+ - Provide ONE short meaning/explanation (≤12 words).
 
23
 
24
  QUOTE rules:
25
+ - After the name line, provide ONE real existing quote about animals, love, companionship, or playfulness.
26
+ - The quote must be authentic (from literature, films, proverbs, or famous people).
27
+ - Keep it short, warm, and not too formal.
28
+ - Translate the quote into the requested language if needed, attribution kept.
29
 
30
  STRICT OUTPUT: exactly two lines
31
  Name — short meaning
 
33
  """
34
 
35
  def build_prompt(species, look, personality, gender, language, inspiration):
 
36
  return f"""
37
  Requested language: {language}
38
  Inspiration source (primary): {inspiration}
39
+ Refinement inputs (secondary):
40
  - Species: {species or '(unspecified)'}
41
  - Appearance: {look or '(unspecified)'}
42
  - Personality: {personality or '(unspecified)'}
43
  - Gender: {gender}
44
 
45
  Task:
46
+ 1) Create EXACTLY ONE cute pet name (≤12-word meaning).
47
+ 2) Then add ONE authentic warm quote about animals/companionship/playfulness.
 
48
  """
49
 
50
  def generate_name(species, look, personality, gender, language, inspiration):
 
57
  )
58
  resp = client.chat.completions.create(
59
  model=MODEL_NAME,
60
+ temperature=0.9, # 提高创造力
61
  top_p=0.95,
62
+ max_tokens=280,
63
  messages=[
64
  {"role": "system", "content": SYSTEM_PROMPT},
65
  {"role": "user", "content": prompt}
 
69
  except Exception as e:
70
  return f"⚠️ 出错:{html.escape(str(e))}"
71
 
72
+ # --- Gradio 界面 ---
73
  with gr.Blocks(title="Pawfect Match") as demo:
74
+ gr.Markdown("## 🐾 Pawfect Match|宠物起名机\n选择灵感来源 + 输入信息 → 一键生成一个可爱的名字 + 一句真实名言。")
75
 
76
  species = gr.Textbox(label="宠物种类", placeholder="例:金毛 / 英短 / 仓鼠 / 鹦鹉(可留空)")
77
  look = gr.Textbox(label="外表特征", placeholder="例:橘色短毛,大眼睛,白爪(可留空)")