PHBJT commited on
Commit
b5f75f8
1 Parent(s): 65ea63c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -91,17 +91,26 @@ def format_description(raw_description, do_format=True):
91
  if not do_format:
92
  return raw_description
93
 
 
 
 
 
 
 
 
 
 
94
  messages = [{
95
  "role": "user",
96
- "content": f"""Format this voice description exactly as:
97
- "a [gender] with a [pitch] voice speaks [speed] in a [environment], [delivery style]"
98
 
99
- Required format:
100
- - gender must be: man/woman
101
- - pitch must be: slightly low-pitched/moderate pitch/high-pitched
102
- - speed must be: slowly/moderately/quickly
103
- - environment must be: close-sounding and clear/distant-sounding and noisy
104
- - delivery style must be: with monotone delivery/with animated delivery
105
 
106
  Input: {raw_description}
107
 
@@ -111,7 +120,6 @@ Return only the formatted description, nothing else."""
111
  outputs = pipe(messages, max_new_tokens=100)
112
  formatted = outputs[0]["generated_text"][-1]["content"].strip()
113
 
114
- # Validate and extract formatted description
115
  if "a woman" in formatted.lower() or "a man" in formatted.lower():
116
  return formatted
117
  return raw_description
 
91
  if not do_format:
92
  return raw_description
93
 
94
+ # Extract defaults from the raw description or use fallbacks
95
+ defaults = {
96
+ "gender": "woman" if "woman" in raw_description.lower() else "man",
97
+ "pitch": "moderate pitch",
98
+ "speed": "slowly",
99
+ "environment": "close-sounding and clear",
100
+ "delivery": "with monotone delivery"
101
+ }
102
+
103
  messages = [{
104
  "role": "user",
105
+ "content": f"""Format this voice description and fill in any missing parameters with defaults:
106
+ "a [gender] with a [pitch] voice speaks [speed] in a [environment], [delivery]"
107
 
108
+ Required parameters (use these exact terms):
109
+ - gender: {defaults['gender']} if not specified
110
+ - pitch: {defaults['pitch']} if not specified
111
+ - speed: {defaults['speed']} if not specified
112
+ - environment: {defaults['environment']} if not specified
113
+ - delivery: {defaults['delivery']} if not specified
114
 
115
  Input: {raw_description}
116
 
 
120
  outputs = pipe(messages, max_new_tokens=100)
121
  formatted = outputs[0]["generated_text"][-1]["content"].strip()
122
 
 
123
  if "a woman" in formatted.lower() or "a man" in formatted.lower():
124
  return formatted
125
  return raw_description