Spaces:
Runtime error
Runtime error
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import time
|
| 4 |
+
import signal
|
| 5 |
+
import psutil
|
| 6 |
+
import io
|
| 7 |
+
|
| 8 |
+
from fastapi import FastAPI, Request, status, Form, UploadFile
|
| 9 |
+
from fastapi.staticfiles import StaticFiles
|
| 10 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
+
from pydantic import BaseModel, Field
|
| 12 |
+
from fastapi.exceptions import RequestValidationError
|
| 13 |
+
from fastapi.responses import JSONResponse
|
| 14 |
+
|
| 15 |
+
import fn
|
| 16 |
+
|
| 17 |
+
app = FastAPI()
|
| 18 |
+
|
| 19 |
+
app.add_middleware(
|
| 20 |
+
CORSMiddleware,
|
| 21 |
+
allow_origins=['*'],
|
| 22 |
+
allow_credentials=True,
|
| 23 |
+
allow_methods=["*"],
|
| 24 |
+
allow_headers=["*"],
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
fn.load_model('large-v3')
|
| 29 |
+
|
| 30 |
+
@app.post("/transcribe")
|
| 31 |
+
async def transcribe_audio(file: UploadFile = Form(...)):
|
| 32 |
+
try:
|
| 33 |
+
file_content = await file.read()
|
| 34 |
+
file_stream = io.BytesIO(file_content)
|
| 35 |
+
|
| 36 |
+
text_only, text_with_timestamps = speech_to_text(file_stream)
|
| 37 |
+
|
| 38 |
+
return {"transcription": text_only, "text_with_timestamps": text_with_timestamps}
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return {"error": str(e)}
|