Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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
|
97 |
-
"a [gender] with a [pitch] voice speaks [speed] in a [environment], [delivery
|
98 |
|
99 |
-
Required
|
100 |
-
- gender
|
101 |
-
- pitch
|
102 |
-
- speed
|
103 |
-
- environment
|
104 |
-
- 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
|