Sigurdur commited on
Commit
1d7558a
verified
1 Parent(s): 9048751

Upload folder using huggingface_hub

Browse files
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8
+ h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9
+ 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10
+ A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11
+ T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12
+ B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13
+ B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14
+ KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJ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xgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
- title: Llama Rjochtwurd
3
- emoji: 馃捇
4
- colorFrom: purple
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.6.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Rjochtwurd
3
+ emoji: 馃悽
4
+ colorFrom: red
5
+ colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 5.6.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: Frisian Text-to-Speech Error Correction
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
+ import torch
4
+ import gradio as gr
5
+
6
+ from peft import PeftModel
7
+
8
+ lora_wheights = "slugroom/llama_rjochtwurd"
9
+ base_model_id = "meta-llama/Llama-3.2-3B"
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id)
12
+
13
+ # to save the model and tokenizer to huggingface hub
14
+ print("saving model and tokenizer")
15
+
16
+ model = AutoModelForCausalLM.from_pretrained(base_model_id)
17
+ model = PeftModel.from_pretrained(model, lora_wheights, torch_dtype=torch.float16, quantization_config=BitsAndBytesConfig(load_in_8bit=True)).to("cpu")
18
+
19
+
20
+ # model_id = "slugroom/llama_rjochtwurd"
21
+ # tokenizer = AutoTokenizer.from_pretrained(model_id)
22
+ # model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16).to("cpu")
23
+
24
+ asr = pipeline("automatic-speech-recognition", "wietsedv/wav2vec2-large-xlsr-53-frisian", device="cpu")
25
+
26
+ def speech_to_text(speech):
27
+ text = asr(speech)["text"]
28
+ return text
29
+
30
+ def correct_errors(text):
31
+ in_txt = f"The following is a Frisian audio transcription, some parts of the transcription may be incorrect. Correct the transcription by making it grammatically and phonetically accurate.\n ### Transcription: {text} \n ### Corrected:"
32
+ model_inputs = tokenizer([in_txt], return_tensors="pt")
33
+
34
+ generated_ids = model.generate(**model_inputs, max_new_tokens=100, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id, do_sample=True, temperature=0.5, top_k=50)
35
+
36
+ # remove prompt from generated text
37
+ generated_ids = generated_ids[:, model_inputs["input_ids"].shape[-1]:]
38
+
39
+ corrected = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
40
+
41
+ print(corrected)
42
+ if "###" in corrected:
43
+ corrected = corrected.split("###")[0]
44
+
45
+
46
+ return corrected
47
+
48
+
49
+ demo = gr.Blocks()
50
+
51
+ with demo:
52
+ gr.HTML("<h1>Frision Speech-to-Text Error Correction</h1>")
53
+ gr.HTML("<p>Upload an audio file in Frisian and press 'Transcribe Audio' to transcribe the audio. The transcription will appear in the text box below. You can also type Frisian text in the text box to be corrected and press 'Correct Errors' to correct the text.</p>")
54
+ gr.HTML("<p>Note that correcting the errors may take up to a minute.</p>")
55
+
56
+ audio_file = gr.Audio(type="filepath", label="Upload Audio File")
57
+ gr.Examples([["./samples/1.mp3"], ["./samples/2.mp3"], ["./samples/3.mp3"], ["./samples/4.mp3"]], audio_file, label="Example Audio Files")
58
+ text = gr.Textbox(placeholder="Transcription will appear here... Additionally type Frisian here to be corrected", label="Transcription")
59
+ gr.Examples([["ik wit net w锚rt 没nder skoraaf"],["hiy it is mei jammer"], ["ast myn frou de earenijen hinne e litte wol is it hare saak"], ["d锚r wiene hiel wat sasjalisten yn frysl芒n"]], text, label="Examples of Frisian Transcriptions")
60
+ audio_file.upload(fn=speech_to_text, inputs=audio_file, outputs=text)
61
+
62
+ corrected_text = gr.Textbox(interactive=False, label="Corrected Transcription")
63
+
64
+ with gr.Row():
65
+ b1 = gr.Button("Transcribe Audio")
66
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
67
+
68
+ b2 = gr.Button("Correct Errors")
69
+ b2.click(correct_errors, inputs=text, outputs=corrected_text)
70
+
71
+ demo.launch(server_port=5000)
72
+
73
+
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ torch==2.5.1
2
+ torchaudio==2.5.1
3
+ torchvision==0.20.1
4
+ transformers==4.46.2
5
+ numpy==1.26.4
6
+ gradio==5.6.0
7
+ bitsandbytes==0.42.0
8
+ PySoundFile
9
+ llama-stack
10
+ peft==0.13.2
samples/.DS_Store ADDED
Binary file (6.15 kB). View file
 
samples/1.mp3 ADDED
Binary file (38.1 kB). View file
 
samples/2.mp3 ADDED
Binary file (36.3 kB). View file
 
samples/3.mp3 ADDED
Binary file (16.9 kB). View file
 
samples/4.mp3 ADDED
Binary file (28.3 kB). View file