yellowcandle commited on
Commit
e648c2d
1 Parent(s): c7d8815

added proofread function

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -35,10 +35,37 @@ def transcribe_audio(audio, model_id):
35
  result = pipe(audio)
36
  return result["text"]
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- demo = gr.Interface(fn=transcribe_audio,
40
- inputs=[gr.Audio(sources="upload", type="filepath"), gr.Dropdown(choices=["openai/whisper-large-v3", "alvanlii/whisper-small-cantonese"])],
41
- outputs="text")
 
 
 
 
 
 
 
 
 
42
  demo.launch()
43
 
44
 
 
35
  result = pipe(audio)
36
  return result["text"]
37
 
38
+ @spaces.GPU(duration=60)
39
+ def proofread(text):
40
+ if text is None:
41
+ return "Please provide the transcribed text for proofreading."
42
+
43
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
44
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
45
+
46
+ model = AutoModelForCausalLM.from_pretrained("hfl/llama-3-chinese-8b-instruct-v3")
47
+ model.to(device)
48
+
49
+ # Perform proofreading using the model
50
+ input_ids = model.tokenizer.encode(text, return_tensors="pt").to(device)
51
+ output = model.generate(input_ids, max_length=len(input_ids[0])+50, num_return_sequences=1, temperature=0.7)
52
+ proofread_text = model.tokenizer.decode(output[0], skip_special_tokens=True)
53
+
54
+ return proofread_text
55
+
56
 
57
+ demo = gr.Interface(
58
+ [transcribe_audio, proofread],
59
+ [
60
+ gr.Audio(sources="upload", type="filepath"),
61
+ gr.Dropdown(choices=["openai/whisper-large-v3", "alvanlii/whisper-small-cantonese"]),
62
+ "text"
63
+ ],
64
+ "text",
65
+ allow_flagging="never",
66
+ title="Audio Transcription and Proofreading",
67
+ description="Upload an audio file, select a model for transcription, and then proofread the transcribed text.",
68
+ )
69
  demo.launch()
70
 
71