Update app.py
Browse files
app.py
CHANGED
|
@@ -29,15 +29,11 @@ def format_time(milliseconds):
|
|
| 29 |
return f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"
|
| 30 |
|
| 31 |
def format_transcript(transcript_string):
|
| 32 |
-
# Regex pattern for speaker labels
|
| 33 |
speaker_label_pattern = r"^(.+?)(?=\s\d{2}:\d{2}:\d{2})"
|
| 34 |
-
# Regex pattern for timestamps
|
| 35 |
timestamp_pattern = r"(\d{2}:\d{2}:\d{2})"
|
| 36 |
-
# Replace speaker labels with bold syntax
|
| 37 |
formatted_transcript = re.sub(
|
| 38 |
speaker_label_pattern, r"**\1**", transcript_string, flags=re.MULTILINE
|
| 39 |
)
|
| 40 |
-
# Replace timestamps with italicized syntax
|
| 41 |
formatted_transcript = re.sub(
|
| 42 |
timestamp_pattern, r"_\1_", formatted_transcript, flags=re.MULTILINE
|
| 43 |
)
|
|
@@ -45,22 +41,25 @@ def format_transcript(transcript_string):
|
|
| 45 |
|
| 46 |
def transcribe_audio(audio_file):
|
| 47 |
if audio_file is None:
|
| 48 |
-
return "Please upload an audio file."
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
def launch_app():
|
| 66 |
iface = gr.Interface(
|
|
|
|
| 29 |
return f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"
|
| 30 |
|
| 31 |
def format_transcript(transcript_string):
|
|
|
|
| 32 |
speaker_label_pattern = r"^(.+?)(?=\s\d{2}:\d{2}:\d{2})"
|
|
|
|
| 33 |
timestamp_pattern = r"(\d{2}:\d{2}:\d{2})"
|
|
|
|
| 34 |
formatted_transcript = re.sub(
|
| 35 |
speaker_label_pattern, r"**\1**", transcript_string, flags=re.MULTILINE
|
| 36 |
)
|
|
|
|
| 37 |
formatted_transcript = re.sub(
|
| 38 |
timestamp_pattern, r"_\1_", formatted_transcript, flags=re.MULTILINE
|
| 39 |
)
|
|
|
|
| 41 |
|
| 42 |
def transcribe_audio(audio_file):
|
| 43 |
if audio_file is None:
|
| 44 |
+
return "Please upload an audio file.", None
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
transcript = create_assembly_transcript(audio_file)
|
| 48 |
+
|
| 49 |
+
if transcript.error:
|
| 50 |
+
return f"An error occurred: {transcript.error}", None
|
| 51 |
+
|
| 52 |
+
transcript_string = transcript_to_string(transcript)
|
| 53 |
+
md_transcript = format_transcript(transcript_string)
|
| 54 |
+
|
| 55 |
+
# Save the markdown transcript to a temporary file
|
| 56 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.md') as temp_file:
|
| 57 |
+
temp_file.write(md_transcript)
|
| 58 |
+
temp_file_path = temp_file.name
|
| 59 |
+
|
| 60 |
+
return md_transcript, temp_file_path
|
| 61 |
+
except Exception as e:
|
| 62 |
+
return f"An error occurred: {str(e)}", None
|
| 63 |
|
| 64 |
def launch_app():
|
| 65 |
iface = gr.Interface(
|