abidlabs HF staff commited on
Commit
2243ed6
β€’
1 Parent(s): c891b07
.ipynb_checkpoints/Untitled-checkpoint.ipynb ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "564964b0",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import string\n",
11
+ "\n",
12
+ "original_string = \"This is a \\t test string with \\n whitespace.\"\n",
13
+ "\n",
14
+ "# Create a generator that filters out whitespace and count removed characters\n",
15
+ "filtered_chars = (char for char in original_string if char not in string.whitespace)\n",
16
+ "no_whitespace_string = \"\".join(filtered_chars)\n",
17
+ "removed_chars_count = sum(1 for char in original_string if char in string.whitespace)\n",
18
+ "\n",
19
+ "print(f\"String without whitespace: '{no_whitespace_string}'\")\n",
20
+ "print(f\"Number of removed characters: {removed_chars_count}\")\n"
21
+ ]
22
+ }
23
+ ],
24
+ "metadata": {
25
+ "kernelspec": {
26
+ "display_name": "Python 3.12",
27
+ "language": "python",
28
+ "name": "python3"
29
+ }
30
+ },
31
+ "nbformat": 4,
32
+ "nbformat_minor": 5
33
+ }
Untitled.ipynb ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "933bf3ba",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "String without whitespace: 'Thisisateststringwithwhitespace.'\n",
14
+ "Number of removed characters: 10\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import string\n",
20
+ "\n",
21
+ "original_string = \"This is a \\t test string with \\n whitespace.\"\n",
22
+ "\n",
23
+ "# Create a generator that filters out whitespace and count removed characters\n",
24
+ "filtered_chars = (char for char in original_string if char not in string.whitespace)\n",
25
+ "no_whitespace_string = \"\".join(filtered_chars)\n",
26
+ "removed_chars_count = sum(1 for char in original_string if char in string.whitespace)\n",
27
+ "\n",
28
+ "print(f\"String without whitespace: '{no_whitespace_string}'\")\n",
29
+ "print(f\"Number of removed characters: {removed_chars_count}\")\n"
30
+ ]
31
+ }
32
+ ],
33
+ "metadata": {
34
+ "kernelspec": {
35
+ "display_name": "Python 3.12",
36
+ "language": "python",
37
+ "name": "python3"
38
+ },
39
+ "language_info": {
40
+ "codemirror_mode": {
41
+ "name": "ipython",
42
+ "version": 3
43
+ },
44
+ "file_extension": ".py",
45
+ "mimetype": "text/x-python",
46
+ "name": "python",
47
+ "nbconvert_exporter": "python",
48
+ "pygments_lexer": "ipython3",
49
+ "version": "3.12.2"
50
+ }
51
+ },
52
+ "nbformat": 4,
53
+ "nbformat_minor": 5
54
+ }
__pycache__/app.cpython-312.pyc CHANGED
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
 
__pycache__/clean.cpython-312.pyc CHANGED
Binary files a/__pycache__/clean.cpython-312.pyc and b/__pycache__/clean.cpython-312.pyc differ
 
__pycache__/utils.cpython-312.pyc CHANGED
Binary files a/__pycache__/utils.cpython-312.pyc and b/__pycache__/utils.cpython-312.pyc differ
 
app.py CHANGED
@@ -11,10 +11,11 @@ css = """
11
 
12
  with gr.Blocks(theme="base", css=css) as demo:
13
  gr.Markdown("<center><h1> πŸ”Š Transcription <span class='cursive-text'>Delight</span> </h1></center>")
14
- gr.Markdown("### Step 1: Generate Raw Transcript")
15
  with gr.Row():
16
  with gr.Column():
17
- source = gr.Radio(label="Source type", choices=[("Audio", "audio"), ("Video", "video"), ("YouTube URL", "youtube")], value="audio")
 
 
18
  @gr.render(inputs=source)
19
  def show_source(s):
20
  if s == "audio":
@@ -31,46 +32,47 @@ with gr.Blocks(theme="base", css=css) as demo:
31
  [source, source_component],
32
  [download_audio],
33
  show_progress="minimal"
 
 
 
 
34
  ).then(
35
  transcribe.transcribe,
36
  [download_audio],
37
  [preliminary_transcript],
38
- ).then(
39
- lambda : [gr.Button(interactive=True), gr.CheckboxGroup(interactive=True)],
 
40
  None,
41
- [clean_btn, cleanup_options]
 
 
 
 
 
42
  )
43
 
44
  with gr.Column():
45
  with gr.Row():
46
- transcribe_btn = gr.Button("Transcribe audio πŸ“œ", variant="primary")
47
- download_audio = gr.DownloadButton("Download .mp3 File πŸ“₯", interactive=False)
48
- preliminary_transcript = gr.Textbox(info="Raw transcript", lines=10, max_lines=10, show_copy_button=True, show_label=False, interactive=False)
 
 
49
 
50
  source.change(utils.transcribe_button, source, transcribe_btn)
51
 
52
- gr.Markdown("### Step 2: Clean with an LLM")
53
- with gr.Row():
54
- with gr.Column():
55
- cleanup_options = gr.CheckboxGroup(label="Cleanup Transcript with LLM", choices=["Remove typos", "Separate into paragraphs"])
56
- llm_prompt = gr.Textbox(label="LLM Prompt", visible=False, lines=3)
57
- cleanup_options.change(
58
- utils.generate_prompt,
59
- cleanup_options,
60
- llm_prompt
61
- )
62
- with gr.Row():
63
- clean_btn = gr.Button("Clean transcript ✨", variant="primary")
64
- download_md = gr.DownloadButton("Download .md πŸ“₯", interactive=False)
65
-
66
- with gr.Column():
67
- final_transcript = gr.Markdown("*Final transcript will appear here*", height=400)
68
-
69
- clean_btn.click(
70
- clean.clean_transcript,
71
- [download_audio, cleanup_options, llm_prompt, preliminary_transcript],
72
- [final_transcript, download_md],
73
- show_progress="minimal"
74
- )
75
 
76
  demo.launch()
 
11
 
12
  with gr.Blocks(theme="base", css=css) as demo:
13
  gr.Markdown("<center><h1> πŸ”Š Transcription <span class='cursive-text'>Delight</span> </h1></center>")
 
14
  with gr.Row():
15
  with gr.Column():
16
+ with gr.Row():
17
+ source = gr.Radio(label="Source type", choices=[ ("YouTube URL", "youtube"), ("Audio", "audio"), ("Video", "video")], value="youtube")
18
+ cleanup_options = gr.CheckboxGroup(label="Cleanup Transcript with LLM", choices=["Remove typos", "Separate into paragraphs"])
19
  @gr.render(inputs=source)
20
  def show_source(s):
21
  if s == "audio":
 
32
  [source, source_component],
33
  [download_audio],
34
  show_progress="minimal"
35
+ ).success(
36
+ lambda : gr.Accordion(open=True),
37
+ None,
38
+ raw_accordion
39
  ).then(
40
  transcribe.transcribe,
41
  [download_audio],
42
  [preliminary_transcript],
43
+ show_progress="minimal"
44
+ ).success(
45
+ lambda : (gr.Accordion(open=False), gr.Accordion(open=True)),
46
  None,
47
+ [raw_accordion, final_accordion]
48
+ ).then(
49
+ clean.clean_transcript,
50
+ [download_audio, cleanup_options, llm_prompt, preliminary_transcript],
51
+ [final_transcript, download_md],
52
+ show_progress="minimal"
53
  )
54
 
55
  with gr.Column():
56
  with gr.Row():
57
+ transcribe_btn = gr.Button("Transcribe πŸ“œ", variant="primary")
58
+ with gr.Accordion("Raw transcript", open=False) as raw_accordion:
59
+ preliminary_transcript = gr.Markdown("*Raw transcript will appear here*", show_label=False, height=400)
60
+ with gr.Accordion("Final transcript", open=False) as final_accordion:
61
+ final_transcript = gr.Markdown("*Final transcript will appear here*", height=400)
62
 
63
  source.change(utils.transcribe_button, source, transcribe_btn)
64
 
65
+ with gr.Accordion("βš™οΈ Settings and Files", open=False) as settings_accordion:
66
+ with gr.Row():
67
+ with gr.Column():
68
+ llm_prompt = gr.Textbox(label="LLM Prompt", visible=False, lines=3)
69
+ cleanup_options.change(
70
+ utils.generate_prompt,
71
+ cleanup_options,
72
+ [llm_prompt, settings_accordion]
73
+ )
74
+ with gr.Row():
75
+ download_audio = gr.DownloadButton("Download .mp3 File πŸ“₯", interactive=False)
76
+ download_md = gr.DownloadButton("Download .md πŸ“₯", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  demo.launch()
clean.py CHANGED
@@ -1,7 +1,6 @@
1
  from huggingface_hub import InferenceClient
2
  from pathlib import Path
3
  import gradio as gr
4
- import os
5
 
6
  MODEL_NAME = "meta-llama/Meta-Llama-3-70b-Instruct"
7
 
@@ -20,10 +19,10 @@ def clean_transcript(audio_file, options, prompt, transcript: str):
20
  messages = [
21
  {"role": "user", "content": prompt + "\n" + chunk}
22
  ]
23
- client = InferenceClient(model=MODEL_NAME, token=os.getenv("HF_TOKEN"))
24
  for c in client.chat_completion(messages, max_tokens=1000, stream=True):
25
  token = c.choices[0].delta.content
26
- text += token
27
  yield text, None
28
 
29
  # write text to md file
 
1
  from huggingface_hub import InferenceClient
2
  from pathlib import Path
3
  import gradio as gr
 
4
 
5
  MODEL_NAME = "meta-llama/Meta-Llama-3-70b-Instruct"
6
 
 
19
  messages = [
20
  {"role": "user", "content": prompt + "\n" + chunk}
21
  ]
22
+ client = InferenceClient(model=MODEL_NAME)
23
  for c in client.chat_completion(messages, max_tokens=1000, stream=True):
24
  token = c.choices[0].delta.content
25
+ text += token or ""
26
  yield text, None
27
 
28
  # write text to md file
utils.py CHANGED
@@ -42,10 +42,7 @@ def convert_video_to_audio(input_file):
42
  gr.Error(f"An error occurred: {e}")
43
 
44
  def transcribe_button(source):
45
- if source == "audio":
46
- return gr.Button("Transcribe audio πŸ“œ")
47
- else:
48
- return gr.Button("Transcribe video πŸ“œ")
49
 
50
  def generate_audio(source, source_file):
51
  if source == "audio":
@@ -61,11 +58,11 @@ def generate_audio(source, source_file):
61
  def generate_prompt(cleanup):
62
  prompt = "The following is a raw transcript from an automatic transcription system. "
63
  if not cleanup:
64
- return gr.Textbox(visible=False)
65
  elif "Remove typos" in cleanup:
66
  prompt += "Fix the minor typos (e.g. misspellings, homophones) in the transcript so that the transcript reads more logically. "
67
  if "Separate into paragraphs" in cleanup:
68
  prompt += "Separate the transcript into paragraphs to make it more readable. "
69
  prompt += "Don't add any extra words in your response, like 'Here is the corrected transcript:' just return the final transcript."
70
- return gr.Textbox(visible=True, value=prompt)
71
 
 
42
  gr.Error(f"An error occurred: {e}")
43
 
44
  def transcribe_button(source):
45
+ return gr.Button("Transcribe πŸ“œ")
 
 
 
46
 
47
  def generate_audio(source, source_file):
48
  if source == "audio":
 
58
  def generate_prompt(cleanup):
59
  prompt = "The following is a raw transcript from an automatic transcription system. "
60
  if not cleanup:
61
+ return gr.Textbox(visible=False), gr.Accordion(open=False)
62
  elif "Remove typos" in cleanup:
63
  prompt += "Fix the minor typos (e.g. misspellings, homophones) in the transcript so that the transcript reads more logically. "
64
  if "Separate into paragraphs" in cleanup:
65
  prompt += "Separate the transcript into paragraphs to make it more readable. "
66
  prompt += "Don't add any extra words in your response, like 'Here is the corrected transcript:' just return the final transcript."
67
+ return gr.Textbox(visible=True, value=prompt), gr.Accordion(open=True)
68