mrbeliever commited on
Commit
279371f
1 Parent(s): 90d5434

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -37,8 +37,12 @@ async def generate1(prompt):
37
  output = ""
38
  for response in stream:
39
  output += response.token.text
40
- output = output.strip('</s>')
41
- yield output
 
 
 
 
42
 
43
  communicate = edge_tts.Communicate(output)
44
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
@@ -64,8 +68,12 @@ async def generate2(prompt):
64
  output = ""
65
  for response in stream:
66
  output += response.token.text
67
- output = output.strip('</s>')
68
- yield output
 
 
 
 
69
 
70
  communicate = edge_tts.Communicate(output)
71
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
@@ -91,8 +99,12 @@ async def generate3(prompt):
91
  output = ""
92
  for response in stream:
93
  output += response.token.text
94
- output = output.strip('</s>')
95
- yield output
 
 
 
 
96
 
97
  communicate = edge_tts.Communicate(output)
98
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
 
37
  output = ""
38
  for response in stream:
39
  output += response.token.text
40
+
41
+ # Clean the output to remove extraneous characters
42
+ output = re.sub(r'[\s/]+', ' ', output).strip()
43
+ output = re.sub(r'\s*$', '', output).strip() # Remove trailing whitespaces
44
+ if output.endswith(' s'):
45
+ output = output[:-2].strip() # Remove trailing ' s'
46
 
47
  communicate = edge_tts.Communicate(output)
48
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
 
68
  output = ""
69
  for response in stream:
70
  output += response.token.text
71
+
72
+ # Clean the output to remove extraneous characters
73
+ output = re.sub(r'[\s/]+', ' ', output).strip()
74
+ output = re.sub(r'\s*$', '', output).strip() # Remove trailing whitespaces
75
+ if output.endswith(' s'):
76
+ output = output[:-2].strip() # Remove trailing ' s'
77
 
78
  communicate = edge_tts.Communicate(output)
79
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
 
99
  output = ""
100
  for response in stream:
101
  output += response.token.text
102
+
103
+ # Clean the output to remove extraneous characters
104
+ output = re.sub(r'[\s/]+', ' ', output).strip()
105
+ output = re.sub(r'\s*$', '', output).strip() # Remove trailing whitespaces
106
+ if output.endswith(' s'):
107
+ output = output[:-2].strip() # Remove trailing ' s'
108
 
109
  communicate = edge_tts.Communicate(output)
110
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file: