fffiloni commited on
Commit
dce42cf
·
verified ·
1 Parent(s): 9065d18

add an image description for future image gen

Browse files
Files changed (1) hide show
  1. app.py +43 -19
app.py CHANGED
@@ -26,31 +26,44 @@ def llama_gen_fragrance(scene):
26
  You are a poetic perfumer. Your role is to create the imaginary scent of a described scene.
27
  You must always respond using the following structure:
28
  ---
29
- Perfume Name:
30
  An original, evocative, and unique name — in French or English.
31
- Tagline:
 
32
  A short, poetic sentence — like a perfume advertisement hook.
33
- Poetic Olfactory Description:
 
34
  A freeform and expressive description of the scent ambiance evoked by the scene. Use rich sensory, emotional, and metaphorical language. Match the **emotional tone** of the scene: if the mood is calm, sleepy, or melancholic, avoid overly bright or energetic expressions. If the scene is painted or artistic, evoke texture, stillness, or material details rather than action or movement. Be subtle and precise.
35
  **Important:** Any scents, herbs, or natural elements mentioned here must be consistent with the scene’s setting. Do not invent new locations or scenery that do not appear in the description.
 
36
  Olfactory Pyramid (technical):
37
- - Top Notes:
38
  List 3–4 real, concrete scent materials that would be perceived first. These must be plausible fragrance ingredients (e.g. herbs, resins, citrus peels, spices, aldehydes, etc.). Pick notes that reflect the **real mood, climate, and setting** of the scene. Do not add locations or elements that don’t appear in the scene. If the scene is indoors or includes human presence, include soft, intimate, or textural notes.
39
- - Heart Notes:
 
40
  List 3–4 real fragrance elements that give body and soul to the perfume. They must relate directly to the **core emotion, human presence, or material textures** of the scene (e.g. warm fabric, skin, dry flowers, books, wood, canvas). If you mention herbs, flowers, or other elements in the poetic description, include them here.
41
- - Base Notes:
 
42
  List 3–4 real, longer-lasting ingredients such as woods, musks, resins, or earthy accords. These should evoke the **depth, texture, or after-image** of the scene — warmth, silence, stillness, or time passing. Avoid generic bases unless they fit the mood. If the scene suggests furniture, old rooms, or human presence, reflect that with realistic base notes.
43
- **Consistency Rule:**
 
44
  The top, heart, and base notes must not introduce new ideas, plants, or places that were not in the poetic description or the scene. Make sure all notes match elements that appear in either the scene or your poetic text.
45
- General Atmosphere:
 
46
  Summarize the fragrance’s evolution and overall emotional impression. Keep it artistic, connected to the real details of the scene, and avoid clichés.
 
 
 
 
47
  ---
48
  Always ensure that:
49
- – The fragrance matches the mood and visual setting of the scene
50
- – All ingredients are real, plausible, and fit together naturally
51
- – No invented scenery or extra context is added
52
- – The poetic description and pyramid share the same notes and details
 
53
  – Each perfume feels unique and consistent
 
54
  Here is the scene description to analyze:
55
  \n<</SYS>>\n\n{} [/INST]"""
56
 
@@ -69,27 +82,38 @@ def parse_perfume_description(text: str) -> dict:
69
  # Perfume Name
70
  perfume_name = re.search(r'Perfume Name:\s*(.+)', text).group(1).strip()
71
 
72
- # Tagline (still expects quotes)
73
  tagline = re.search(r'Tagline:\s*"(.*?)"', text, re.DOTALL)
74
  tagline = tagline.group(1).strip() if tagline else ""
75
 
76
- # Poetic Olfactory Description: allow quoted or plain
77
  poetic_desc_match = re.search(
78
  r'Poetic Olfactory Description:\s*"(.*?)"', text, re.DOTALL)
79
  if poetic_desc_match:
80
  poetic_desc = poetic_desc_match.group(1).strip()
81
  else:
82
- # fallback: get everything until next section
83
  poetic_desc_match = re.search(
84
- r'Poetic Olfactory Description:\s*(.*?)\s*Olfactory Pyramid:', text, re.DOTALL)
 
85
  poetic_desc = poetic_desc_match.group(1).strip() if poetic_desc_match else ""
86
 
87
- # General Atmosphere: same idea
 
 
 
 
 
 
 
 
 
 
 
88
  general_atmosphere_match = re.search(
89
  r'General Atmosphere:\s*(.+)', text, re.DOTALL)
90
  general_atmosphere = general_atmosphere_match.group(1).strip() if general_atmosphere_match else ""
91
 
92
- # Flexible note extractor for bullet points
93
  def extract_notes(section_name):
94
  pattern = rf'{section_name}:\s*\n((?:\*.*(?:\n|$))+)'
95
  match = re.search(pattern, text, re.MULTILINE)
@@ -99,7 +123,6 @@ def parse_perfume_description(text: str) -> dict:
99
  notes = []
100
  for line in notes_text.strip().splitlines():
101
  bullet = line.strip().lstrip('*').strip()
102
- # If it has ":", split note & description
103
  if ':' in bullet:
104
  note, desc = bullet.split(':', 1)
105
  notes.append({'note': note.strip(), 'description': desc.strip()})
@@ -115,6 +138,7 @@ def parse_perfume_description(text: str) -> dict:
115
  'Perfume Name': perfume_name,
116
  'Tagline': tagline,
117
  'Poetic Olfactory Description': poetic_desc,
 
118
  'Olfactory Pyramid': {
119
  'Top Notes': top_notes,
120
  'Heart Notes': heart_notes,
 
26
  You are a poetic perfumer. Your role is to create the imaginary scent of a described scene.
27
  You must always respond using the following structure:
28
  ---
29
+ Perfume Name:
30
  An original, evocative, and unique name — in French or English.
31
+
32
+ Tagline:
33
  A short, poetic sentence — like a perfume advertisement hook.
34
+
35
+ Poetic Olfactory Description:
36
  A freeform and expressive description of the scent ambiance evoked by the scene. Use rich sensory, emotional, and metaphorical language. Match the **emotional tone** of the scene: if the mood is calm, sleepy, or melancholic, avoid overly bright or energetic expressions. If the scene is painted or artistic, evoke texture, stillness, or material details rather than action or movement. Be subtle and precise.
37
  **Important:** Any scents, herbs, or natural elements mentioned here must be consistent with the scene’s setting. Do not invent new locations or scenery that do not appear in the description.
38
+
39
  Olfactory Pyramid (technical):
40
+ - Top Notes:
41
  List 3–4 real, concrete scent materials that would be perceived first. These must be plausible fragrance ingredients (e.g. herbs, resins, citrus peels, spices, aldehydes, etc.). Pick notes that reflect the **real mood, climate, and setting** of the scene. Do not add locations or elements that don’t appear in the scene. If the scene is indoors or includes human presence, include soft, intimate, or textural notes.
42
+
43
+ - Heart Notes:
44
  List 3–4 real fragrance elements that give body and soul to the perfume. They must relate directly to the **core emotion, human presence, or material textures** of the scene (e.g. warm fabric, skin, dry flowers, books, wood, canvas). If you mention herbs, flowers, or other elements in the poetic description, include them here.
45
+
46
+ - Base Notes:
47
  List 3–4 real, longer-lasting ingredients such as woods, musks, resins, or earthy accords. These should evoke the **depth, texture, or after-image** of the scene — warmth, silence, stillness, or time passing. Avoid generic bases unless they fit the mood. If the scene suggests furniture, old rooms, or human presence, reflect that with realistic base notes.
48
+
49
+ Consistency Rule:
50
  The top, heart, and base notes must not introduce new ideas, plants, or places that were not in the poetic description or the scene. Make sure all notes match elements that appear in either the scene or your poetic text.
51
+
52
+ General Atmosphere:
53
  Summarize the fragrance’s evolution and overall emotional impression. Keep it artistic, connected to the real details of the scene, and avoid clichés.
54
+
55
+ Image Description (for marketing visuals):
56
+ Describe an imagined marketing image that captures the perfume’s essence. The image must always prominently depict the perfume bottle as the main subject, designed to reflect the mood, material textures, and atmosphere of the scene. Use the codes and conventions of luxury perfume advertising: the image should feel cinematic, poetic, and evocative — not literal. Refer only to elements present in the scene or poetic description: colors, textures, props, atmosphere, light, and materials. Avoid adding any new locations, characters, or objects that do not fit the described scene. Focus on mood, composition, visual style, and the perfume bottle’s design and placement within the scene (e.g. glass type, cap, label, subtle details that match the setting).
57
+
58
  ---
59
  Always ensure that:
60
+ – The fragrance matches the mood and visual setting of the scene
61
+ – All ingredients are real, plausible, and fit together naturally
62
+ – No invented scenery or extra context is added
63
+ – The poetic description and pyramid share the same notes and details
64
+ – The image description always depicts a perfume bottle as the main subject, designed in harmony with the scene
65
  – Each perfume feels unique and consistent
66
+
67
  Here is the scene description to analyze:
68
  \n<</SYS>>\n\n{} [/INST]"""
69
 
 
82
  # Perfume Name
83
  perfume_name = re.search(r'Perfume Name:\s*(.+)', text).group(1).strip()
84
 
85
+ # Tagline (quoted)
86
  tagline = re.search(r'Tagline:\s*"(.*?)"', text, re.DOTALL)
87
  tagline = tagline.group(1).strip() if tagline else ""
88
 
89
+ # Poetic Olfactory Description: quoted or plain
90
  poetic_desc_match = re.search(
91
  r'Poetic Olfactory Description:\s*"(.*?)"', text, re.DOTALL)
92
  if poetic_desc_match:
93
  poetic_desc = poetic_desc_match.group(1).strip()
94
  else:
 
95
  poetic_desc_match = re.search(
96
+ r'Poetic Olfactory Description:\s*(.*?)\s*(Olfactory Pyramid:|Image Description:|General Atmosphere:)',
97
+ text, re.DOTALL)
98
  poetic_desc = poetic_desc_match.group(1).strip() if poetic_desc_match else ""
99
 
100
+ # Image Description: quoted or plain
101
+ image_desc_match = re.search(
102
+ r'Image Description:\s*"(.*?)"', text, re.DOTALL)
103
+ if image_desc_match:
104
+ image_desc = image_desc_match.group(1).strip()
105
+ else:
106
+ image_desc_match = re.search(
107
+ r'Image Description:\s*(.*?)\s*(Olfactory Pyramid:|Poetic Olfactory Description:|General Atmosphere:)',
108
+ text, re.DOTALL)
109
+ image_desc = image_desc_match.group(1).strip() if image_desc_match else ""
110
+
111
+ # General Atmosphere
112
  general_atmosphere_match = re.search(
113
  r'General Atmosphere:\s*(.+)', text, re.DOTALL)
114
  general_atmosphere = general_atmosphere_match.group(1).strip() if general_atmosphere_match else ""
115
 
116
+ # Flexible bullet extractor
117
  def extract_notes(section_name):
118
  pattern = rf'{section_name}:\s*\n((?:\*.*(?:\n|$))+)'
119
  match = re.search(pattern, text, re.MULTILINE)
 
123
  notes = []
124
  for line in notes_text.strip().splitlines():
125
  bullet = line.strip().lstrip('*').strip()
 
126
  if ':' in bullet:
127
  note, desc = bullet.split(':', 1)
128
  notes.append({'note': note.strip(), 'description': desc.strip()})
 
138
  'Perfume Name': perfume_name,
139
  'Tagline': tagline,
140
  'Poetic Olfactory Description': poetic_desc,
141
+ 'Image Description': image_desc,
142
  'Olfactory Pyramid': {
143
  'Top Notes': top_notes,
144
  'Heart Notes': heart_notes,