File size: 1,487 Bytes
de95cc5
 
 
 
 
 
 
 
 
 
 
 
 
 
808f6a8
 
de95cc5
 
 
 
 
 
 
 
 
 
 
808f6a8
de95cc5
 
 
 
 
 
 
 
 
84ab0c3
de95cc5
 
 
 
00f6f1d
 
b22bcbc
00f6f1d
b22bcbc
00f6f1d
 
 
 
d3eb718
 
5c4beda
d3eb718
5c4beda
d3eb718
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import sys
import time
import signal
import io

from fastapi import FastAPI, Request, status, Form, UploadFile
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel, Field
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse

import fn
import gradio as gr
from app import demo

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

gr.mount_gradio_app(app, demo, path="/gradio")

fn.load_model('large-v3')

@app.post("/transcribe")
async def transcribe_audio(file: UploadFile = Form(...)):
    try:
        file_content = await file.read()
        file_stream = io.BytesIO(file_content)

        text_only, text_with_timestamps = fn.speech_to_text(file_stream)

        return {"transcription": text_only, "text_with_timestamps": text_with_timestamps}
    except Exception as e:
        return {"error": str(e)}

@app.post("/set_prompt")
async def set_prompt(prompt: str, language: str = None):
    try:
        fn.set_prompt(prompt, language)

        return {"status": 0}
    except Exception as e:
        return {"error": str(e)}

@app.post("/set_transcribe_args")
async def set_transcribe_kwargs(args: dict):
    try:
        fn.set_transcribe_kwargs(args)

        return {"status": 0}
    except Exception as e:
        return {"error": str(e)}