Spaces:
Sleeping
Sleeping
Hugo Rodrigues
commited on
Commit
·
8ae43fc
1
Parent(s):
590ca00
add log to find response time
Browse files
main.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from typing import Union
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from fastapi import FastAPI
|
|
@@ -33,15 +35,22 @@ pipe = pipeline("automatic-speech-recognition",
|
|
| 33 |
|
| 34 |
@app.get("/device")
|
| 35 |
def getDevice():
|
|
|
|
|
|
|
|
|
|
| 36 |
return device
|
| 37 |
|
| 38 |
|
| 39 |
@app.get("/transcribe")
|
| 40 |
def transcribe(inputs, task):
|
|
|
|
|
|
|
| 41 |
if inputs is None:
|
| 42 |
raise "No audio file submitted! Please upload or record an audio file before submitting your request."
|
| 43 |
|
| 44 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={
|
| 45 |
"task": task}, return_timestamps=True)["text"]
|
| 46 |
|
|
|
|
|
|
|
| 47 |
return text
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
from uvicorn.config import LOGGING_CONFIG
|
| 3 |
from typing import Union
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from fastapi import FastAPI
|
|
|
|
| 35 |
|
| 36 |
@app.get("/device")
|
| 37 |
def getDevice():
|
| 38 |
+
start_time = time.time()
|
| 39 |
+
print("Time took to process the request and return response is {} sec".format(
|
| 40 |
+
time.time() - start_time))
|
| 41 |
return device
|
| 42 |
|
| 43 |
|
| 44 |
@app.get("/transcribe")
|
| 45 |
def transcribe(inputs, task):
|
| 46 |
+
start_time = time.time()
|
| 47 |
+
|
| 48 |
if inputs is None:
|
| 49 |
raise "No audio file submitted! Please upload or record an audio file before submitting your request."
|
| 50 |
|
| 51 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={
|
| 52 |
"task": task}, return_timestamps=True)["text"]
|
| 53 |
|
| 54 |
+
print("Time took to process the request and return response is {} sec".format(
|
| 55 |
+
time.time() - start_time))
|
| 56 |
return text
|