簡體   English   中英

如何使我的 Haskell 功能在我的 Python Flask 應用程序中可用?

[英]How do I make my Haskell functions available in my Python Flask app?

我有一個用 Haskell 編寫的機器學習 model,但想在前端使用 Python 和 Z9784E91C7B2657917226BC。 如何從我的 Python Z9784E91C7B2657917Z926BC8 一些代碼示例會有所幫助 - 到目前為止,我已經查看了 Servant,但不知道這將如何與 Flask 應用程序一起工作。

如果您正在尋找一種相當快速的方法來為您的機器學習 model 建立基於 Web 的界面,正如 FifthCode 所建議的那樣,您可能需要考慮Scotty 這是一個受 Sinatra 啟發的 web 框架,適用於 Haskell。

{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty

import Data.Monoid (mconcat)

main = scotty 3000 $
    get "/:word" $ do
        beam <- param "word"
        html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]

值得注意的是,像這樣使用 REST API 的調用將阻塞。 Depending on how long it takes your machine learning model to run, you may want to use aa webhook approach where you submit a job with HTTP/HTTPS and include a webhook URL on your flask app that the Scotty app will POST to when it has finished運行 model。

當您的 Flask 應用程序 POST 到 Scotty 應用程序上的 /predict 時,它將最終阻塞,直到 Scotty 應用程序響應。 讓 Scotty 應用程序為 ML 工作生成一個線程,然后立即以 204 Accepted 響應,然后 ML 線程 POST 到 Flask 應用程序上的 /prediction 並在其完成時顯示結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM