PHBJT commited on
Commit
44bb8b9
1 Parent(s): 03d612a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -50,34 +50,40 @@ def format_description(raw_description, do_format=True):
50
  return raw_description
51
 
52
  messages = [{
 
 
 
53
  "role": "user",
54
- "content": f"""Format this voice description to match exactly:
55
  "a [gender] with a [pitch] voice speaks [speed] in a [environment], [delivery style]"
56
- Where:
 
57
  - gender: man/woman
58
  - pitch: slightly low-pitched/moderate pitch/high-pitched
59
- - speed: slowly/moderately/quickly
60
  - environment: close-sounding and clear/distant-sounding and noisy
61
  - delivery style: with monotone delivery/with animated delivery
62
- Description to format: {raw_description}"""
 
 
 
63
  }]
64
 
65
  input_text = smol_tokenizer.apply_chat_template(messages, tokenize=False)
66
  inputs = smol_tokenizer.encode(input_text, return_tensors="pt").to(device)
67
  outputs = smol_model.generate(
68
  inputs,
69
- max_new_tokens=200,
70
- temperature=0.7,
71
  top_p=0.9,
72
  do_sample=True
73
  )
74
  formatted = smol_tokenizer.decode(outputs[0], skip_special_tokens=True)
75
 
76
- # Extract the formatted description from the response
77
- try:
78
- return formatted.split("a ")[-1].strip()
79
- except:
80
- return raw_description
81
 
82
  def preprocess(text):
83
  text = number_normalizer(text).strip()
 
50
  return raw_description
51
 
52
  messages = [{
53
+ "role": "system",
54
+ "content": "You are a helpful assistant that formats voice descriptions precisely according to the template provided."
55
+ }, {
56
  "role": "user",
57
+ "content": f"""Format this voice description exactly as:
58
  "a [gender] with a [pitch] voice speaks [speed] in a [environment], [delivery style]"
59
+
60
+ Required format:
61
  - gender: man/woman
62
  - pitch: slightly low-pitched/moderate pitch/high-pitched
63
+ - speed: slowly/moderately/quickly
64
  - environment: close-sounding and clear/distant-sounding and noisy
65
  - delivery style: with monotone delivery/with animated delivery
66
+
67
+ Input description: {raw_description}
68
+
69
+ Return only the formatted description, nothing else."""
70
  }]
71
 
72
  input_text = smol_tokenizer.apply_chat_template(messages, tokenize=False)
73
  inputs = smol_tokenizer.encode(input_text, return_tensors="pt").to(device)
74
  outputs = smol_model.generate(
75
  inputs,
76
+ max_new_tokens=100,
77
+ temperature=0.2,
78
  top_p=0.9,
79
  do_sample=True
80
  )
81
  formatted = smol_tokenizer.decode(outputs[0], skip_special_tokens=True)
82
 
83
+ # Extract just the formatted description
84
+ if "a woman" in formatted.lower() or "a man" in formatted.lower():
85
+ return formatted.strip()
86
+ return raw_description
 
87
 
88
  def preprocess(text):
89
  text = number_normalizer(text).strip()