abidlabs HF staff commited on
Commit
fe8d4db
1 Parent(s): add165b
__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 ADDED
Binary file (1.96 kB). View file
 
__pycache__/transcribe.cpython-312.pyc CHANGED
Binary files a/__pycache__/transcribe.cpython-312.pyc and b/__pycache__/transcribe.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
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import utils
 
3
  import transcribe
4
 
5
  with gr.Blocks(theme="base") as demo:
@@ -18,26 +19,27 @@ with gr.Blocks(theme="base") as demo:
18
  source_component = gr.Textbox(placeholder="https://www.youtube.com/watch?v=44vi31hehw4")
19
  preview = gr.HTML(label="Video preview")
20
  source_component.change(utils.convert_to_embed_url, source_component, preview)
21
- # transcribe_btn.click(
22
- # lambda : gr.Tabs(selected="result"),
23
- # None,
24
- # tabs
25
- # ).then(
26
- # utils.generate_audio,
27
- # [source, source_component],
28
- # [download_audio],
29
- # show_progress="minimal"
30
- # ).then(
31
- # transcribe.transcribe,
32
- # [download_audio],
33
- # [preliminary_transcript],
34
- # show_progress="hidden"
35
- # )
36
 
37
- with gr.Column():
38
- transcribe_btn = gr.Button("Transcribe audio 📜", variant="primary")
39
- preliminary_transcript = gr.Textbox(info="Raw transcript", lines=10, show_copy_button=True, show_label=False, interactive=False)
 
 
 
 
 
 
 
 
 
 
 
40
 
 
 
 
 
 
41
 
42
  source.change(utils.transcribe_button, source, transcribe_btn)
43
 
@@ -51,15 +53,18 @@ with gr.Blocks(theme="base") as demo:
51
  cleanup_options,
52
  llm_prompt
53
  )
 
 
 
54
 
55
  with gr.Column():
56
- clean_btn = gr.Button("Clean transcript ✨", variant="primary", interactive=False)
57
- gr.Markdown("*Final transcript will appear here*")
58
- # with gr.Tab("Result", id="result"):
59
- # with gr.Row():
60
- # with gr.Column():
61
- # download_audio = gr.DownloadButton("Downloading Audio File (please wait...)", variant="primary", interactive=False, size="sm")
62
- # preliminary_transcript = gr.Textbox(info="Raw transcript", lines=10, show_copy_button=True, show_label=False, interactive=False)
63
- # with gr.Column():
64
 
65
  demo.launch()
 
1
  import gradio as gr
2
  import utils
3
+ import clean
4
  import transcribe
5
 
6
  with gr.Blocks(theme="base") as demo:
 
19
  source_component = gr.Textbox(placeholder="https://www.youtube.com/watch?v=44vi31hehw4")
20
  preview = gr.HTML(label="Video preview")
21
  source_component.change(utils.convert_to_embed_url, source_component, preview)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ transcribe_btn.click(
24
+ utils.generate_audio,
25
+ [source, source_component],
26
+ [download_audio],
27
+ show_progress="minimal"
28
+ ).then(
29
+ transcribe.transcribe,
30
+ [download_audio],
31
+ [preliminary_transcript],
32
+ ).then(
33
+ lambda : [gr.Button(interactive=True), gr.CheckboxGroup(interactive=True)],
34
+ None,
35
+ [clean_btn, cleanup_options]
36
+ )
37
 
38
+ with gr.Column():
39
+ with gr.Row():
40
+ transcribe_btn = gr.Button("Transcribe audio 📜", variant="primary")
41
+ download_audio = gr.DownloadButton("Download .mp3 File 📥", interactive=False)
42
+ preliminary_transcript = gr.Textbox(info="Raw transcript", lines=10, max_lines=10, show_copy_button=True, show_label=False, interactive=False)
43
 
44
  source.change(utils.transcribe_button, source, transcribe_btn)
45
 
 
53
  cleanup_options,
54
  llm_prompt
55
  )
56
+ with gr.Row():
57
+ clean_btn = gr.Button("Clean transcript ✨", variant="primary")
58
+ download_md = gr.DownloadButton("Download .md 📥", interactive=False)
59
 
60
  with gr.Column():
61
+ final_transcript = gr.Markdown("*Final transcript will appear here*", height=400)
62
+
63
+ clean_btn.click(
64
+ clean.clean_transcript,
65
+ [download_audio, cleanup_options, llm_prompt, preliminary_transcript],
66
+ [final_transcript, download_md],
67
+ show_progress="minimal"
68
+ )
69
 
70
  demo.launch()
clean.py CHANGED
@@ -1,12 +1,31 @@
1
  from huggingface_hub import InferenceClient
 
 
2
 
3
  MODEL_NAME = "meta-llama/Meta-Llama-3-70b-Instruct"
4
 
5
- def clean_transcript(prompt, transcript):
6
- messages = [
7
- {"role": "user", "content": PROMPT}
8
- ]
9
- client = InferenceClient(model=MODEL_NAME)
10
- for c in client.chat_completion(messages, max_tokens=200, stream=True):
11
- token = c.choices[0].delta.content
12
- print(token, end="")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
7
+ def split_text_into_chunks(text, chunk_size=600):
8
+ words = text.split()
9
+ chunks = [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
10
+ return chunks
11
+
12
+ def clean_transcript(audio_file, options, prompt, transcript: str):
13
+ text = f"### {Path(audio_file).with_suffix('').name}\n\n"
14
+ if options == []:
15
+ text += transcript
16
+ else:
17
+ chunks = split_text_into_chunks(transcript)
18
+ for chunk in chunks:
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
26
+ yield text, None
27
+
28
+ # write text to md file
29
+ md_file = Path(audio_file).with_suffix('.md')
30
+ md_file.write_text(text)
31
+ return text, gr.DownloadButton(interactive=True, value=md_file)
utils.py CHANGED
@@ -56,15 +56,16 @@ def generate_audio(source, source_file):
56
  else:
57
  gr.Info("Downloading audio from YouTube...")
58
  audio_file = download_audio_from_youtube(source_file)
59
- return gr.DownloadButton("Downloading Audio File", value=audio_file, interactive=True)
60
 
61
  def generate_prompt(cleanup):
 
62
  if not cleanup:
63
  return gr.Textbox(visible=False)
64
- elif cleanup == ["Remove typos"]:
65
- return gr.Textbox(visible=True, placeholder="The following is a raw transcript from an automatic transcription system. Remove the typos from the transcript.")
66
- elif cleanup == ["Separate into paragraphs"]:
67
- return gr.Textbox(visible=True, placeholder="The following is a raw transcript from an automatic transcription system. Separate the transcript into paragraphs based on logical breaks.")
68
- elif cleanup == ["Remove typos", "Separate into paragraphs"]:
69
- return gr.Textbox(visible=True, placeholder="The following is a raw transcript from an automatic transcription system. Remove the typos and separate the transcript into paragraphs based on logical breaks.")
70
 
 
56
  else:
57
  gr.Info("Downloading audio from YouTube...")
58
  audio_file = download_audio_from_youtube(source_file)
59
+ return gr.DownloadButton(value=audio_file, interactive=True)
60
 
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