2023-10-03 22:09:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-03-14 20:06:34 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2023-10-03 22:09:38 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
2023-10-05 20:31:16 +00:00
|
|
|
"github.com/labstack/echo/v4/middleware"
|
2023-10-03 22:09:38 +00:00
|
|
|
"github.com/labstack/gommon/log"
|
2023-10-05 18:05:30 +00:00
|
|
|
"github.com/xzeldon/whisper-api-server/internal/api"
|
|
|
|
"github.com/xzeldon/whisper-api-server/internal/resources"
|
2023-10-03 22:09:38 +00:00
|
|
|
)
|
|
|
|
|
2024-03-19 17:00:05 +00:00
|
|
|
func change_working_directory(e *echo.Echo) {
|
2024-03-14 20:06:34 +00:00
|
|
|
exePath, errs := os.Executable()
|
|
|
|
if errs != nil {
|
|
|
|
e.Logger.Error(errs)
|
|
|
|
return
|
2023-10-03 22:09:38 +00:00
|
|
|
}
|
|
|
|
|
2024-03-14 20:06:34 +00:00
|
|
|
exeDir := filepath.Dir(exePath)
|
|
|
|
|
|
|
|
// Change the working directory to the executable directory
|
|
|
|
errs = os.Chdir(exeDir)
|
|
|
|
if errs != nil {
|
|
|
|
e.Logger.Error(errs)
|
|
|
|
return
|
2023-10-05 18:05:30 +00:00
|
|
|
}
|
|
|
|
|
2024-03-14 20:06:34 +00:00
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
fmt.Println("Current working directory:", cwd)
|
2024-03-19 17:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
e := echo.New()
|
|
|
|
e.HideBanner = true
|
|
|
|
change_working_directory(e)
|
|
|
|
|
|
|
|
args, errParsing := resources.ParseFlags()
|
|
|
|
if errParsing != nil {
|
|
|
|
e.Logger.Error("Error parsing flags: ", errParsing)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Use(middleware.CORS())
|
2024-03-14 20:06:34 +00:00
|
|
|
|
|
|
|
if l, ok := e.Logger.(*log.Logger); ok {
|
|
|
|
l.SetHeader("${time_rfc3339} ${level}")
|
2023-10-05 18:05:30 +00:00
|
|
|
}
|
|
|
|
|
2024-03-14 20:06:34 +00:00
|
|
|
whisperState, err := api.InitializeWhisperState(args.ModelPath, args.Language)
|
|
|
|
|
2023-10-03 22:09:38 +00:00
|
|
|
if err != nil {
|
|
|
|
e.Logger.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
e.POST("/v1/audio/transcriptions", func(c echo.Context) error {
|
2024-03-14 20:06:34 +00:00
|
|
|
|
2023-10-05 18:05:30 +00:00
|
|
|
return api.Transcribe(c, whisperState)
|
2023-10-03 22:09:38 +00:00
|
|
|
})
|
|
|
|
|
2024-03-19 17:00:05 +00:00
|
|
|
e.Logger.Fatal(e.Start(fmt.Sprintf("127.0.0.1:%d", args.Port)))
|
2023-10-03 22:09:38 +00:00
|
|
|
}
|