Spaces:
Sleeping
Sleeping
yellowcandle
commited on
Commit
•
d1c3a70
1
Parent(s):
f6b2f01
fix errors
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline, Aut
|
|
8 |
def transcribe_audio(audio, model_id):
|
9 |
if audio is None:
|
10 |
return "Please upload an audio file."
|
|
|
|
|
11 |
|
12 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
13 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
@@ -34,21 +36,24 @@ def transcribe_audio(audio, model_id):
|
|
34 |
result = pipe(audio)
|
35 |
return result["text"]
|
36 |
|
37 |
-
@spaces.GPU(duration=
|
38 |
-
def proofread(text):
|
39 |
if text is None:
|
40 |
return "Please provide the transcribed text for proofreading."
|
41 |
|
42 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
43 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
44 |
|
|
|
|
|
45 |
model = AutoModelForCausalLM.from_pretrained("hfl/llama-3-chinese-8b-instruct-v3")
|
|
|
46 |
model.to(device)
|
47 |
|
48 |
# Perform proofreading using the model
|
49 |
-
input_ids =
|
50 |
output = model.generate(input_ids, max_length=len(input_ids[0])+50, num_return_sequences=1, temperature=0.7)
|
51 |
-
proofread_text =
|
52 |
|
53 |
return proofread_text
|
54 |
|
@@ -59,7 +64,7 @@ with gr.Blocks() as demo:
|
|
59 |
|
60 |
with gr.Row():
|
61 |
audio = gr.Audio(sources="upload", type="filepath")
|
62 |
-
model_dropdown = gr.Dropdown(choices=["openai/whisper-large-v3", "alvanlii/whisper-small-cantonese"])
|
63 |
|
64 |
transcribe_button = gr.Button("Transcribe")
|
65 |
transcribed_text = gr.Textbox(label="Transcribed Text")
|
|
|
8 |
def transcribe_audio(audio, model_id):
|
9 |
if audio is None:
|
10 |
return "Please upload an audio file."
|
11 |
+
if model_id is None:
|
12 |
+
return "Please select a model."
|
13 |
|
14 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
15 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
|
|
36 |
result = pipe(audio)
|
37 |
return result["text"]
|
38 |
|
39 |
+
@spaces.GPU(duration=180)
|
40 |
+
def proofread(prompt, text):
|
41 |
if text is None:
|
42 |
return "Please provide the transcribed text for proofreading."
|
43 |
|
44 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
45 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
46 |
|
47 |
+
prompt = "用繁體中文整理這段文字,在最後加上整段文字的重點。"
|
48 |
+
|
49 |
model = AutoModelForCausalLM.from_pretrained("hfl/llama-3-chinese-8b-instruct-v3")
|
50 |
+
tokenizer = AutoTokenizer.from_pretrained("hfl/llama-3-chinese-8b-instruct-v3")
|
51 |
model.to(device)
|
52 |
|
53 |
# Perform proofreading using the model
|
54 |
+
input_ids = tokenizer.encode(text, return_tensors="pt").to(device)
|
55 |
output = model.generate(input_ids, max_length=len(input_ids[0])+50, num_return_sequences=1, temperature=0.7)
|
56 |
+
proofread_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
57 |
|
58 |
return proofread_text
|
59 |
|
|
|
64 |
|
65 |
with gr.Row():
|
66 |
audio = gr.Audio(sources="upload", type="filepath")
|
67 |
+
model_dropdown = gr.Dropdown(choices=["openai/whisper-large-v3", "alvanlii/whisper-small-cantonese"], value="openai/whisper-large-v3")
|
68 |
|
69 |
transcribe_button = gr.Button("Transcribe")
|
70 |
transcribed_text = gr.Textbox(label="Transcribed Text")
|