Build a speech transcription demo with OpenAI’s Whisper model in-browser using Transformers.js

Transformers.js

Transformers.js is a Javascript implementation of the Python library transformers, which was developed by HuggingFace. Transformers.js uses ONNX Runtime to run pre-trained AI models with JavaScript. Basically, ONNX Runtime performs better on edge or low-end devices with its ONNX models compared to PyTorch, TensorFlow, and other similar frameworks. ONNX Runtime will be introduced in detail in another post. For now, we will focus on implementing a Transformers.js demo instead of diving deep into the background.

Common tasks supported by Transformers.js:

  • Natural Language Processing: text classification, named entity recognition, question answering, language modelling, summarization, translation, multiple choice, and text generation.
  • Computer Vision: image classification, object detection, segmentation, and depth estimation.
  • Audio: automatic speech recognition, audio classification, and text-to-speech.
  • Multimodal: embeddings, zero-shot audio classification, zero-shot image classification, and zero-shot object detection
    Continue reading Build a speech transcription demo with OpenAI’s Whisper model in-browser using Transformers.js

Use Azure Devops Pipeline to build && deploy your project

this post will teach you how to deploy your own Docker registry and how to use Microsoft Azure Devops to automatically building your Github Go project, and deploy to your Docker Swarm Server

How it works

Use Azure Devops Pipeline to build && deploy your project - 1

  1. Pipeline download your github project
  2. Build your code by Dockerfile, make docker image then push to your own Docker registry
  3. Execute Bash command in Pipeline, pull off latest image of your project then update Docker swarm service

Continue reading Use Azure Devops Pipeline to build && deploy your project

Write a Microservice via Go-Micro

I’ve learning Go-Micro around a month, that I wanna write an article to record what I have learnt. In case I forgot it, I can still pick it up by reading this article. What I have wrote about might be inaccurate, I’m very glad that you can correct it.

Architecture

Write a Microservice via Go-Micro - 1

my design about Microservices architecture

Continue reading Write a Microservice via Go-Micro

websocket nginx reverse proxy configuration

location /test {
        proxy_pass http://127.0.0.1:8080/ws; # target address

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        # websocket headers
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 30;
}

Echo frameworks context bind twice without losing data

Retrieve data from echo middleware, may cause you get code=400, message=EOF error.

Context.Bind only can bind once, after the request passed the middleware,the request data reader is running out, Context.Bind() function read request body data from the socket buffer, once you took it out, it just gone

that’s why it returns EOF error.

solution

func main() {
    echoServer := echo.New()
    echoServer.POST("/api", webfunc1, middleware1)
    echoServer.Start(":8080")
}

func middleware1(next echo.HandlerFunc) echo.HandlerFunc {
    return func(c echo.Context) error {
        // read origin body bytes
        var bodyBytes []byte
        if c.Request().Body != nil {
            bodyBytes, _ = ioutil.ReadAll(c.Request().Body)
            // write back to request body
            c.Request().Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
            // parse json data
            reqData := struct {
                ID string `json:"id"`
            }{}
            err := json.Unmarshal(bodyBytes, &reqData)
            if err != nil {
                return c.JSON(400, "error json.")
            }
            fmt.Println(reqData.ID)
        }
        return next(c)
    }
}

func webfunc1(c echo.Context) error {
    reqData := struct {
        Data string `json:"data"`
    }{}
    c.Bind(&reqData)
    fmt.Println(reqData.Data)
    return c.HTML(200, "200 OK.")
}

Golang: Read from an io.ReadWriter without losing its content