Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,26 +14,30 @@ def transcribe_audio(audio_file):
|
|
14 |
return transcription["text"]
|
15 |
|
16 |
# Function to correct grammar in text
|
17 |
-
def
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Function to process the pipeline
|
39 |
def process_pipeline(audio_file):
|
|
|
14 |
return transcription["text"]
|
15 |
|
16 |
# Function to correct grammar in text
|
17 |
+
def chunk_text(text, max_tokens=2000):
|
18 |
+
"""
|
19 |
+
Splits the text into smaller chunks to ensure it doesn't exceed the token limit.
|
20 |
+
"""
|
21 |
+
words = text.split()
|
22 |
+
chunks = []
|
23 |
+
chunk = []
|
24 |
+
current_tokens = 0
|
25 |
+
|
26 |
+
for word in words:
|
27 |
+
word_tokens = len(word.split()) # Approximate token count
|
28 |
+
if current_tokens + word_tokens > max_tokens:
|
29 |
+
chunks.append(" ".join(chunk))
|
30 |
+
chunk = [word]
|
31 |
+
current_tokens = word_tokens
|
32 |
+
else:
|
33 |
+
chunk.append(word)
|
34 |
+
current_tokens += word_tokens
|
35 |
+
|
36 |
+
if chunk:
|
37 |
+
chunks.append(" ".join(chunk))
|
38 |
+
|
39 |
+
return chunks
|
40 |
+
|
41 |
|
42 |
# Function to process the pipeline
|
43 |
def process_pipeline(audio_file):
|