Spaces:
Sleeping
Sleeping
VenkateshRoshan
commited on
Commit
·
f461359
1
Parent(s):
9a3f61d
Initial Commit
Browse files
app.py
CHANGED
@@ -91,7 +91,8 @@ import os
|
|
91 |
from transformers import pipeline
|
92 |
from huggingface_hub import InferenceClient
|
93 |
import time
|
94 |
-
import torch
|
|
|
95 |
|
96 |
# Ensure CUDA is available and set device accordingly
|
97 |
# device = 0 if torch.cuda.is_available() else -1
|
@@ -102,21 +103,25 @@ pipe = pipeline("automatic-speech-recognition", model=model_id) #, device=device
|
|
102 |
|
103 |
def transcribe(inputs, use_api):
|
104 |
start = time.time()
|
|
|
105 |
if inputs is None:
|
106 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
107 |
|
108 |
try:
|
109 |
if use_api:
|
110 |
print(f'Using API for transcription...')
|
|
|
111 |
# Use InferenceClient (API) if checkbox is checked
|
112 |
res = client.automatic_speech_recognition(inputs).text
|
113 |
else:
|
114 |
print(f'Using local pipeline for transcription...')
|
115 |
# Use local pipeline if checkbox is unchecked
|
|
|
116 |
res = pipe(inputs, chunk_length_s=30)["text"]
|
117 |
|
118 |
end = time.time() - start
|
119 |
-
return res, end
|
|
|
120 |
|
121 |
except Exception as e:
|
122 |
return fr'Error: {str(e)}', None
|
|
|
91 |
from transformers import pipeline
|
92 |
from huggingface_hub import InferenceClient
|
93 |
import time
|
94 |
+
# import torch
|
95 |
+
# import numpy as np
|
96 |
|
97 |
# Ensure CUDA is available and set device accordingly
|
98 |
# device = 0 if torch.cuda.is_available() else -1
|
|
|
103 |
|
104 |
def transcribe(inputs, use_api):
|
105 |
start = time.time()
|
106 |
+
API_STATUS = ''
|
107 |
if inputs is None:
|
108 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
109 |
|
110 |
try:
|
111 |
if use_api:
|
112 |
print(f'Using API for transcription...')
|
113 |
+
API_STATUS = 'Using API it took: '
|
114 |
# Use InferenceClient (API) if checkbox is checked
|
115 |
res = client.automatic_speech_recognition(inputs).text
|
116 |
else:
|
117 |
print(f'Using local pipeline for transcription...')
|
118 |
# Use local pipeline if checkbox is unchecked
|
119 |
+
API_STATUS = 'Using local pipeline it took: '
|
120 |
res = pipe(inputs, chunk_length_s=30)["text"]
|
121 |
|
122 |
end = time.time() - start
|
123 |
+
return res, API_STATUS + str(round(end, 2)) + ' seconds'
|
124 |
+
# return res, end
|
125 |
|
126 |
except Exception as e:
|
127 |
return fr'Error: {str(e)}', None
|