Spaces:
Runtime error
Runtime error
Commit
•
08f0765
1
Parent(s):
d6af2ee
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import pipeline
|
4 |
-
from ctransformers import AutoModelForCausalLM
|
5 |
|
6 |
MODEL_NAME = "openai/whisper-tiny"
|
7 |
BATCH_SIZE = 8
|
@@ -15,17 +15,20 @@ pipe = pipeline(
|
|
15 |
device=device,
|
16 |
)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def transcribe(inputs, task = "transcribe"):
|
19 |
if inputs is None:
|
20 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
21 |
|
22 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
23 |
-
return text
|
24 |
|
25 |
-
# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
|
26 |
-
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-v0.1-GGUF", model_file="mistral-7b-v0.1.Q4_K_M.gguf", model_type="mistral", gpu_layers=0)
|
27 |
|
28 |
-
print(llm("AI is going to"))
|
29 |
|
30 |
iface = gr.Interface(
|
31 |
fn=transcribe,
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import pipeline
|
4 |
+
from ctransformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
|
6 |
MODEL_NAME = "openai/whisper-tiny"
|
7 |
BATCH_SIZE = 8
|
|
|
15 |
device=device,
|
16 |
)
|
17 |
|
18 |
+
# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
|
19 |
+
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-v0.1-GGUF", model_file="mistral-7b-v0.1.Q4_K_M.gguf", model_type="mistral", gpu_layers=0)
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(llm)
|
21 |
+
|
22 |
+
llm_pipe = pipeline("text-generation", model=llm, tokenizer=tokenizer)
|
23 |
+
|
24 |
def transcribe(inputs, task = "transcribe"):
|
25 |
if inputs is None:
|
26 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
27 |
|
28 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
29 |
+
return llm_pipe(text, max_new_tokens=256)
|
30 |
|
|
|
|
|
31 |
|
|
|
32 |
|
33 |
iface = gr.Interface(
|
34 |
fn=transcribe,
|