Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,8 +15,25 @@ def transcribe_audio(audio_file):
|
|
15 |
|
16 |
# Function to correct grammar in text
|
17 |
def correct_text(raw_text):
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Function to process the pipeline
|
22 |
def process_pipeline(audio_file):
|
|
|
15 |
|
16 |
# Function to correct grammar in text
|
17 |
def correct_text(raw_text):
|
18 |
+
try:
|
19 |
+
# Chunk the text into smaller pieces if needed (to handle token limits)
|
20 |
+
text_chunks = chunk_text(raw_text, max_tokens=2000)
|
21 |
+
corrected_chunks = []
|
22 |
+
|
23 |
+
for chunk in text_chunks:
|
24 |
+
# Provide clear instructions to the model
|
25 |
+
prompt = f"Correct the following text for grammar and punctuation without changing its meaning: {chunk}"
|
26 |
+
corrected = correction_pipeline(prompt, max_length=2048, num_return_sequences=1)[0]["generated_text"]
|
27 |
+
|
28 |
+
# Add only the corrected part
|
29 |
+
corrected_chunks.append(corrected.strip())
|
30 |
+
|
31 |
+
# Combine corrected chunks
|
32 |
+
final_corrected_text = " ".join(corrected_chunks).strip()
|
33 |
+
return final_corrected_text
|
34 |
+
|
35 |
+
except Exception as e:
|
36 |
+
return f"Error in correction: {str(e)}"
|
37 |
|
38 |
# Function to process the pipeline
|
39 |
def process_pipeline(audio_file):
|