Complete Technical Paper Content โ Ai Fastapi Serving
1. Executive Abstract, Problem Formulation & Background
The Python programming language is actively used by many people, both in industry and academia, for a wide variety of purposes.
Atom โ an open-source cross-platform IDE with autocomplete, help and more Python features under package extensions. Codelobster โ a cross-platform IDE for various languages, including Python. Colab โ Jupyter notebook online integrated development environment developed by Google. EasyEclipse โ an open-source IDE for Python and other languages. Eclipse โ with the Pydev plug-in. Eclipse supports many other languages as well. Emacs, with the built-in python-mode. Eric โ an IDE for Python and Ruby. Geany โ IDE for Python development and other languages. IDLE โ a simple IDE bundled with the default implementation of the language. Jupyter Notebook โ an IDE that supports markdown, Python, Julia โ R and several other languages. Kaggle Notebooks โ an online IDE for Python and R with integrated data science libraries, free GPUs, and collaborative features. Komodo IDE โ an IDE PHOTOS Python, Perl, PHP and Ruby. Neovim โ has python support with pynvim. NetBeans โ is written in Java and runs everywhere where a JVM is installed. PyCharm โ a proprietary and open-source IDE for Python development. PythonAnywhere โ an online IDE and Web hosting service. Python Tools for Visual Studio โ Free and open-source plug-in for Visual Studio. Spyder โ IDE for scientific programming. Thonny โ beginner-friendly Python IDE. Vim โ with "lang#python" layer enabled. Visual Studio Code โ an open-source IDE for various languages, including Python. Wing IDE โ cross-platform proprietary with some free versions/licenses IDE for Python. Replit โ an online IDE that supports multiple languages.
BlueBream โ a rewrite by the Zope developers of the Zope 2 web application server. CherryPy โ an object-oriented web application server and framework. CubicWeb โ a web framework that targets large-scale semantic web and linked open data applications and international corporations. Django โ an MVT (model, view, template) web framework. Flask โ a modern, lightweight, well-documented micro-framework based on Werkzeug and Jinja 2. Google App Engine โ a platform for developing and hosting web applications in Google-managed data centers, including Python. Grok โ a web framework based on Zope Toolkit technology. Nevow โ a web application framework originally developed by the company Divmod. Pylons โ a lightweight web framework emphasizing flexibility and rapid development. Pyramid โ a minimalistic web framework inspired by Zope, Pylons and Django. Quixote โ a framework for developing Web applications in Python. RapidSMS โ a web framework which extends the logic and capabilities of Django to communicate with SMS messages. Spyce โ a technology to embed Python code into webpages. Tornado โ a lightweight non-blocking server and framework. TurboGears โ a web framework combining SQLObject/SQLAlchemy, Kid/Genshi, and CherryPy/Pylons. web2py โ a full-stack enterprise web application framework, following the MVC design. Zope 2 โ an application server, commonly used to build content management systems.
Apache MXNet โ open-source deep learning framework for deep neural networks. Apache Singa โ library for deep learning. Apache SystemDS โ machine learning system for the end-to-end data science lifecycle. Caffe โ deep learning framework. CatBoost โ machine learning library for gradient boosting on decision trees. Chainer โ deep learning framework on top of NumPy and CuPy. Deeplearning4j โ open-source deep learning library for the Java virtual machine. DeepSpeed โ deep learning optimization library. Dlib โ software library with machine learning algorithms. fastText โ library for efficient text classification and word embeddings. Gensim โ library for topic modeling and vector space modeling. H2O โ software for machine learning and predictive analytics. Horovod โ framework by Uber for distributed deep learning training using TensorFlow, Keras, PyTorch, and Apache MXNet. Hugging Face Transformers โ deep learning library for training and running pretrained transformer models. JAX โ software library for machine learning, artificial intelligence, and high-performance numerical computing. Jubatus โ platform for distributed online machine learning. Keras โ high-level neural networks API, running on top of TensorFlow and other backends. LightGBM โ gradient boosting framework. MindSpore โ deep learning framework developed by Huawei. Orange โ open-source data visualization, machine learning, and data mining toolkit. PlaidML โ tensor compiler. PyTorch โ open-source machine learning library based on the Torch library. PyTorch Lightning โ provides a high-level interface for PyTorch. QLattice โ symbolic regression. scikit-learn โ library for machine learning. Spark MLlib โ distributed machine learning library for Apache Spark. TensorFlow โ software library for machine learning and artificial intelligence. Theano โ machine learning library. Transformers Library โ mainly compatible with the PyTorch library from Hugging Face. Vowpal Wabbit โ machine learning system for fast online learning. XGBoost โ gradient boosting library.
Abaqus (Finite Element Software) ADvantage Framework Amarok ArcGIS โ a prominent GIS platform, allows extensive modelling using Python. Autodesk Maya โ a professional 3D modeler allows Python scripting as an alternative to MEL as of version 8.5. Autodesk MotionBuilder Autodesk Softimage (formerly Softimage|XSI) BioNumerics โ a bioinformatics software suite for the management, storage and (statistical) analysis of all types of biological data. Blender Boxee โ a cross-platform home theater PC software. Cinema 4D Civilization IV has the map editor supporting Python. Corel Paint Shop Pro Claws Mail with Python plugin DSHub ERDAS Imagine FL Studio โ a Digital audio workstation, uses Python to support MIDI Controller integration, as well as scripting within its piano roll and Edison audio editor. FreeCAD gedit GIMP GNAT โ The GNAT programming chain tool (Ada language implementation in GNU gcc), as a GNATcoll reusable components for the applications (with or without PyGTK) and as a scripting language for the commands in the GPS programming environment. Houdini highly evolved 3D animation package, fully extensible using python. Inkscape โ a free vector graphics editor. Krita โ a free raster graphics editor for digital painting. MeVisLab โ a medical image processing and visualization software, uses Python for network scripting, macro modules, and application building. Modo Minecraft: Pi Edition (game). MSC.Software's CAE packages: Adams, Mentat, SimXpert. MySQL Workbench โ a visual database design tool. Nuke (compositing for visual effects) OriginPro โ a commercial graphic and analysis software, provides Python environment for access. ParaView, an opensource scientific visualization software Poser โ a 3D rendering and animation computer program that uses for scripting a special dialect of Python, called PoserPython. PTV AG products for traffic and transportation analysis, including PTV VISSIM. PyMOL โ a popular molecular viewer that embeds Python for scripting and integration. OriginPro โ a commercial graphing and analysis software, provides a Python environment for both embedded and external access. QGIS uses Python for scripting and plugin-development. Rhinoceros 3D version 5.0 and its visual-scripting language Grasshopper uses IronPython. Rhythmbox Scribus 3DSlicer โ a medical image visualisation and analysis software. Python is available for algorithm implementation, analysis pipelines, and GUI creation. SPSS statistical software โ SPSS Programmability Extension allows users to extend the SPSS command syntax language with Python. SublimeText Totem โ a media player for the GNOME desktop environment. Vim VisIt WeeChat โ a console IRC client.
CLPython โ Implementation, written in Common Lisp. CPython โ The reference implementation, written in C11. Some notable distributions include: ActivePython โ Distribution with more than 300 included packages. Intel Distribution for Python โ High performance distribution with conda and pip package managers. PSF Python โ Reference distribution that includes only selected standard libraries Cython โ programming language to simplify writing C and C++ extension modules for the CPython Python runtime. IronPython โ Python for CLI platforms (including .NET and Mono). Jython โ Python for Java platforms. MicroPython โ Python 3 implementation for micro-controller platforms. Nuitka โ a source-to-source compiler which compiles Python code to C/C++ executables, or source code. Numba โ NumPy aware LLVM-based JIT compiler. PyPy โ Python (originally) coded in Python, used with RPython, a restricted subset of Python that is amenable to static analysis and thus a JIT. Shed Skin โ a source-to-source compiler from Python to C++. Historic Python implementations include:
2. Related Work, Literature Survey & Algorithmic Foundations
Parrot โ Virtual machine being developed mainly as the runtime for Raku, and intended to support dynamic languages like Python, Ruby, Tcl, etc. Psyco โ specialized JIT compiler project that has mostly been eclipsed by PyPy. Pyrex โ Python-like Python module development project that has mostly been eclipsed by Cython. Python for S60 โ CPython port to the S60 platform. Stackless Python โ CPython with coroutines. Unladen Swallow โ performance-orientated implementation based on CPython which natively executed its bytecode via an LLVM-based JIT compiler. Funded by Google, stopped circa 2011.
Anaconda is an open source data science and artificial intelligence development portal and a distribution platform for the Python programming language. Developed by Anaconda, Inc., an American company founded in 2012, the platform is used to develop and manage data science and AI projects. In 2024, Anaconda Inc. has about 300 employees and 50 million users.
Anaconda Navigator is a desktop graphical user interface (GUI) included in Anaconda distribution that allows users to launch applications and manage Conda packages, environments and channels without using command-line commands. Navigator can search for packages on Anaconda Cloud or in a local Anaconda Repository, install them in an environment, run the packages and update them. It is available for Windows, macOS and Linux. The following applications are available by default in Navigator:
Conda is an open source, cross-platform, language-agnostic package manager and environment management system that installs, runs, and updates packages and their dependencies. It was created for Python programs, but it can package and distribute software for any language, including multi-language projects. The Conda package and environment manager is included in all versions of Anaconda, Miniconda, and Anaconda Repository.
FASTAPI for AI & ML Projects ๐ This repository is a practical playground and professional archive for building and deploying APIs using FastAPI , with a special focus on integrating Machine Learning (ML) , Deep Learning (DL) , and Large Language Models (LLMs) . ๐ฅ Why This Repository? As modern AI systems increasingly require robust and scalable deployment, this repo is a hands-on learning and development space to: Design RESTful APIs for web and database interactions. Build and serve AI/ML/DL/LLM models through FastAPI. Practice production-level API standards and design patterns. ๐ Goals โ Practice building RESTful APIs using FastAPI. โ Integrate databases (e.g., PostgreSQL, MongoDB). ๐ Deploy ML models (scikit-learn, XGBoost, etc.) with FastAPI. ๐ Serve DL models (TensorFlow, PyTorch). ๐ Deploy LLMs with LangChain, HuggingFace, or Groq API. โ Implement Pydantic models for request validation. ๐ Add authentication (JWT, OAuth2). ๐ Write test cases using pytest. ๐งฐ Tech Stack FastAPI โ Web framework Uvicorn โ ASGI server SQLAlchemy โ ORM (for SQL-based projects) MongoDB / PostgreSQL โ Databases Pydantic โ Data validation Docker โ Containerization (future integration) PyTorch / TensorFlow / Scikit-Learn โ AI/ML/DL libraries LangChain / HuggingFace โ LLM integrations ๐ Getting Started 1. Clone the Repository git https://github.com/MDalamin5/FastAPI-for-Machine-Learning-and-Agentic-Ai.git 2. Create and Activate Virtual Environment python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate 3. Install Dependencies pip install -r requirements.txt 4. Run the FastAPI App uvicorn main:app --reload Visit http://127.0.0.1:8000/docs for the Swagger UI. ๐ Example Use Cases User authentication system (JWT based) Prediction API for housing price model Image classification using DL models Chatbot with LangChain and vector stores AI Tutor API for math or science ๐งช Testing pytest tests/ ๐ Learning Resources FastAPI Documentation Full Stack FastAPI PostgreSQL Deployment with Docker & FastAPI LangChain Documentation ๐จโ๐ป Author Al-Amin โ GitHub | LinkedIn ๐ License This project is licensed under the MIT License - see the LICENSE file for details. ๐ Contribute & Star If you find this repo useful or inspiring, feel free to star โญ the project and contribute with ideas, code, or improvements!
This repository is a practical playground and professional archive for building and deploying APIs using FastAPI , with a special focus on integrating Machine Learning (ML) , Deep Learning (DL) , and Large Language Models (LLMs) .
3. Dataset Ingestion, Preprocessing & Stochastic Augmentations
As modern AI systems increasingly require robust and scalable deployment, this repo is a hands-on learning and development space to:
If you find this repo useful or inspiring, feel free to star โญ the project and contribute with ideas, code, or improvements!
A practical FastAPI-based repository for building and deploying APIs, starting from web and database projects to serving ML, DL, and LLM models. Ideal for learning scalable AI deployment and modern API design with Python, Pydantic, and production-ready tools like LangChain and HuggingFace.
FASTAPI for AI & ML Projects ๐ This repository is a practical playground and professional archive for building and deploying APIs using FastAPI , with a special focus on integrating Machine Learning (ML) , Deep Learning (DL) , and Large Language Models (LLMs) . ๐ฅ Why This Repository? As modern AI systems increasingly require robust and scalable deployment, this repo is a hands-on learning and development space to: Design RESTful APIs for web and database interactions. Build and serve AI/ML/DL/LLM models through FastAPI. Practice production-level API standards and design patterns. ๐ Goals โ Practice building RESTful APIs using FastAPI. โ Integrate databases (e.g., PostgreSQL, MongoDB). ๐ Deploy ML models (scikit-learn, XGBoost, etc.) with FastAPI. ๐ Serve DL models (TensorFlow, PyTorch). ๐ Deploy LLMs with LangChain, HuggingFace, or Groq API. โ Implement Pydantic models for request validation. ๐ Add authentication (JWT, OAuth2). ๐ Write test cases using pytest. ๐งฐ Tech Stack FastAPI โ Web framework Uvicorn โ ASGI server SQLAlchemy โ ORM (for SQL-based projects) MongoDB / PostgreSQL โ Databases Pydantic โ Data validation Docker โ Containerization (future integration) PyTorch / TensorFlow / Scikit-Learn โ AI/ML/DL libraries LangChain / HuggingFace โ LLM integrations ๐ Getting Started 1. Clone the Repository git https://github.com/MDalamin5/FastAPI-for-Machine-Learning-and-Agentic-Ai.git 2. Create and Activate Virtual Environment python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate 3. Install Dependencies pip install -r requirements.txt 4. Run the FastAPI App uvicorn main:app --reload Visit http://127.0.0.1:8000/docs for the Swagger UI. ๐ Example Use Cases User authentication system (JWT based) Prediction API for housing price model Image classification using DL models Chatbot with LangChain and vector stores AI Tutor API for math or science ๐งช Testing pytest tests/ ๐ Learning Resources FastAPI Documentation Full Stack FastAPI PostgreSQL Deployment with Docker & FastAPI LangChain Documentation ๐จโ๐ป Author Al-Amin โ GitHub | LinkedIn ๐ License This project is licensed under the MIT License - see the LICENSE file for details. ๐ Contribute & Star If you find this repo useful or inspiring, feel free to star โญ the project and contribute with ideas, code, or improvements!
This repository is a practical playground and professional archive for building and deploying APIs using FastAPI , with a special focus on integrating Machine Learning (ML) , Deep Learning (DL) , and Large Language Models (LLMs) .
As modern AI systems increasingly require robust and scalable deployment, this repo is a hands-on learning and development space to:
4. Neural Network Backbone, Layer Specifications & Loss Formulations
If you find this repo useful or inspiring, feel free to star โญ the project and contribute with ideas, code, or improvements!
A practical FastAPI-based repository for building and deploying APIs, starting from web and database projects to serving ML, DL, and LLM models. Ideal for learning scalable AI deployment and modern API design with Python, Pydantic, and production-ready tools like LangChain and HuggingFace.
2023-10-20.22-57-29.mp4 AI models with FastAPI Streaming and Vercel AI SDK Getting started First of all we need to create our project structure, start by creating a backend and frontend folders: โโโ .env โโโ backend/ โโโ frontend/ Setting up our api: # backend/main.py import uvicorn from os import getenv , path from dotenv import load_dotenv from fastapi import BackgroundTasks , FastAPI , Request , Response app_base = path . dirname ( __file__ ) app_root = path . join ( app_base , '../' ) load_dotenv ( dotenv_path = path . join ( app_root , '.env' )) app_host = getenv ( "APP_HTTP_HOST" ) app_port = int ( getenv ( "APP_HTTP_PORT" )) app = FastAPI () @ app . get ( "/api/reply" ) def reply ( value : str ): print ( f"reply: { value } " ) return { "reply" : value } if __name__ == "__main__" : uvicorn . run ( "main:app" , host = app_host , reload = True , port = app_port ) Create a new vite app inside the frontend folder: yarn create vite --template react-ts Setting up SPA Integration: After creating the back and front projects we neew to combine them together, the easiest way is serve our frontend app as static file from our backend. Also we should setup a SPA Proxy for developing propourses. 1. Setting Up environment variables: Inside the .env file we can place common environment variables for both apps. APP_ENVIRONMENT = ' Development ' APP_HTTP_HOST = ' 127.0.0.1 ' APP_HTTP_PORT = ' 5000 ' APP_HTTP_URL = ' http://${APP_HTTP_HOST}:${APP_HTTP_PORT} ' APP_SPA_PROXY_PORT = ' 3000 ' APP_SPA_PROXY_URL = ' http://${APP_HTTP_HOST}:${APP_SPA_PROXY_PORT} ' APP_SPA_FOLDER_ROOT = ' frontend ' APP_SPA_PROXY_LAUNCH_CMD = ' yarn dev --port ${APP_SPA_PROXY_PORT} ' 2. Configuring vite request proxy: We can now tell vite to proxy all fetch requests to our api endpoint, so that we can to api calls without specify the host server. So our frontend app will behave as hosted by the backend app, even in development environment. Inside the frontend/vite.config.ts add the following: import { env } from "node:process" ; import { defineConfig } from "vite" ; import react from "@vitejs/plugin-react" ; const apiProxyTarget = env . APP_HTTP_URL ; export default defineConfig ( { define : { "process.env" : process . env , _WORKLET : false , __DEV__ : env . DEV , global : { } , } , plugins : [ react ( ) ] , server : { strictPort : true , proxy : { "/api" : { target : apiProxyTarget , changeOrigin : true , secure : false , rewrite : ( path ) => path . replace ( / ^ \/ a p i / , "/api" ) , } , } , } , } ) ; We can test api calls by adding a fetch request inside our App.tsx : import "./App.css" ; import { useEffect , useState } from "react" ; function App ( ) { const [ apiResponse , setApiResponse ] = useState ( "" ) ; useEffect ( ( ) => { fetch ( "/api/reply?value=Hello from React App!" ) . then ( ( response ) => response . json ( ) ) . then ( ( result ) => setApiResponse ( JSON . stringify ( result ) ) ) ; } , [ ] ) ; return ( < div > < code > { apiResponse } </ code > </ div > ) ; } export default App ; 3. Serving the a SPA app from FastAPI: In this step we need to setup our backend to serve the react app as static files in production and proxy when is development. Let's update the backend/main.py import subprocess import uvicorn from os import getenv , path from dotenv import load_dotenv from fastapi import FastAPI , Request from fastapi . responses import RedirectResponse from fastapi . templating import Jinja2Templates from fastapi . staticfiles import StaticFiles app_base = path . dirname ( __file__ ) app_root = path . join ( app_base , '../' ) app_public = path . join ( app_base , "public/" ) load_dotenv ( dotenv_path = path . join ( app_root , '.env' )) app_env = getenv ( "APP_ENVIRONMENT" ) app_host = getenv ( "APP_HTTP_HOST" ) app_port = int ( getenv ( "APP_HTTP_PORT" )) app_spa_folder = path . join ( app_root , getenv ( "APP_SPA_FOLDER_ROOT" )) app_spa_proxy_url = getenv ( "APP_SPA_PROXY_URL" ) app_spa_proxy_launch_cmd = getenv ( "APP_SPA_PROXY_LAUNCH_CMD" ) app = FastAPI () templates = Jinja2Templates ( directory = app_public ) app . mount ( "/public" , StaticFiles ( directory = app_public ), name = "public" ) @ app . get ( "/api/reply" ) def reply ( value : str ): print ( f"reply: { value } " ) return { "reply" : value } @ app . get ( "/{full_path:path}" ) async def serve_spa_app ( request : Request , full_path : str ): """Serve the react app `full_path` variable is necessary to serve each possible endpoint with `index.html` file in order to be compatible with `react-router-dom """ if app_env . lower () == "development" : return RedirectResponse ( app_spa_proxy_url ) return templates . TemplateResponse ( "index.html" , { "request" : request }) if __name__ == "__main__" : # Launching the SPA proxy server if app_env . lower () == "development" : print ( "Launching the SPA proxy server..." , app_spa_folder ) spa_process = subprocess . Popen ( args = app_spa_proxy_launch_cmd . split ( " " ), cwd = app_spa_folder ) uvicorn . run ( "main:app" , host = app_host , reload = True , port = app_port ) That its, now when we run our backend app with python main.py it will also launch our frontend app in develop mode. Also will do fallback all non api routes to our SPA app. Note: In production, we need to publish our frontend's dist files to the public folder inside our backend. You can setup it inside your Dockerfile during some CI/CD routine. Streaming AI results from FastAPI: Now let's add some AI feature to our backend/main.py # Others Imports... from pydantic import BaseModel from langchain . llms . openai import OpenAI from fastapi . responses import StreamingResponse app = FastAPI () llm = OpenAI ( streaming = True , verbose = True , temperature = 0 , openai_api_key = getenv ( "OPENAI_API_KEY" ) ) class Question ( BaseModel ): prompt : str @ app . post ( '/api/ask' ) async def ask ( question : Question ): print ( question ) def generator ( prompt : str ): for item in llm . stream ( prompt ): yield item return StreamingResponse ( generator ( question . prompt ), media_type = 'text/event-stream' ) # More code... That its, we have an AI Asking endpoint with streaming support. Now lets integrate with our frontend app First add the ai package yarn add ai Then update the App.tsx : import "./App.css" ; import { useCompletion } from "ai/react" ; function App ( ) { // Some code here ... const { input , completion , handleInputChange , handleSubmit } = useCompletion ( { api : "/api/ask" , headers : { "Content-Type" : "application/json" , } , } ) ; return ( < div > < form onSubmit = { handleSubmit } > < label htmlFor = "ask-input" > Ask something: </ label > < input id = "ask-input" type = "text" value = { input } onChange = { handleInputChange } /> < button type = "submit" > POST </ button > </ form > < textarea value = { completion } rows = { 20 } > </ textarea > </ div > ) ; } export default App ;
First of all we need to create our project structure, start by creating a backend and frontend folders:
# backend/main.py import uvicorn from os import getenv , path from dotenv import load_dotenv from fastapi import BackgroundTasks , FastAPI , Request , Response app_base = path . dirname ( __file__ ) app_root = path . join ( app_base , '../' ) load_dotenv ( dotenv_path = path . join ( app_root , '.env' )) app_host = getenv ( "APP_HTTP_HOST" ) app_port = int ( getenv ( "APP_HTTP_PORT" )) app = FastAPI () @ app . get ( "/api/reply" ) def reply ( value : str ): print ( f"reply: { value } " ) return { "reply" : value } if __name__ == "__main__" : uvicorn . run ( "main:app" , host = app_host , reload = True , port = app_port )
After creating the back and front projects we neew to combine them together, the easiest way is serve our frontend app as static file from our backend. Also we should setup a SPA Proxy for developing propourses.
5. Training Protocol, Convergence Behavior & Experimental Evaluation
APP_ENVIRONMENT = ' Development ' APP_HTTP_HOST = ' 127.0.0.1 ' APP_HTTP_PORT = ' 5000 ' APP_HTTP_URL = ' http://${APP_HTTP_HOST}:${APP_HTTP_PORT} ' APP_SPA_PROXY_PORT = ' 3000 ' APP_SPA_PROXY_URL = ' http://${APP_HTTP_HOST}:${APP_SPA_PROXY_PORT} ' APP_SPA_FOLDER_ROOT = ' frontend ' APP_SPA_PROXY_LAUNCH_CMD = ' yarn dev --port ${APP_SPA_PROXY_PORT} '
We can now tell vite to proxy all fetch requests to our api endpoint, so that we can to api calls without specify the host server. So our frontend app will behave as hosted by the backend app, even in development environment.
import { env } from "node:process" ; import { defineConfig } from "vite" ; import react from "@vitejs/plugin-react" ; const apiProxyTarget = env . APP_HTTP_URL ; export default defineConfig ( { define : { "process.env" : process . env , _WORKLET : false , __DEV__ : env . DEV , global : { } , } , plugins : [ react ( ) ] , server : { strictPort : true , proxy : { "/api" : { target : apiProxyTarget , changeOrigin : true , secure : false , rewrite : ( path ) => path . replace ( / ^ \/ a p i / , "/api" ) , } , } , } , } ) ;
import "./App.css" ; import { useEffect , useState } from "react" ; function App ( ) { const [ apiResponse , setApiResponse ] = useState ( "" ) ; useEffect ( ( ) => { fetch ( "/api/reply?value=Hello from React App!" ) . then ( ( response ) => response . json ( ) ) . then ( ( result ) => setApiResponse ( JSON . stringify ( result ) ) ) ; } , [ ] ) ; return ( < div > < code > { apiResponse } </ code > </ div > ) ; } export default App ;
In this step we need to setup our backend to serve the react app as static files in production and proxy when is development.
import subprocess import uvicorn from os import getenv , path from dotenv import load_dotenv from fastapi import FastAPI , Request from fastapi . responses import RedirectResponse from fastapi . templating import Jinja2Templates from fastapi . staticfiles import StaticFiles app_base = path . dirname ( __file__ ) app_root = path . join ( app_base , '../' ) app_public = path . join ( app_base , "public/" ) load_dotenv ( dotenv_path = path . join ( app_root , '.env' )) app_env = getenv ( "APP_ENVIRONMENT" ) app_host = getenv ( "APP_HTTP_HOST" ) app_port = int ( getenv ( "APP_HTTP_PORT" )) app_spa_folder = path . join ( app_root , getenv ( "APP_SPA_FOLDER_ROOT" )) app_spa_proxy_url = getenv ( "APP_SPA_PROXY_URL" ) app_spa_proxy_launch_cmd = getenv ( "APP_SPA_PROXY_LAUNCH_CMD" ) app = FastAPI () templates = Jinja2Templates ( directory = app_public ) app . mount ( "/public" , StaticFiles ( directory = app_public ), name = "public" ) @ app . get ( "/api/reply" ) def reply ( value : str ): print ( f"reply: { value } " ) return { "reply" : value } @ app . get ( "/{full_path:path}" ) async def serve_spa_app ( request : Request , full_path : str ): """Serve the react app `full_path` variable is necessary to serve each possible endpoint with `index.html` file in order to be compatible with `react-router-dom """ if app_env . lower () == "development" : return RedirectResponse ( app_spa_proxy_url ) return templates . TemplateResponse ( "index.html" , { "request" : request }) if __name__ == "__main__" : # Launching the SPA proxy server if app_env . lower () == "development" : print ( "Launching the SPA proxy server..." , app_spa_folder ) spa_process = subprocess . Popen ( args = app_spa_proxy_launch_cmd . split ( " " ), cwd = app_spa_folder ) uvicorn . run ( "main:app" , host = app_host , reload = True , port = app_port )
Model Figures & Evaluation Curves (4 Images)
Deep Learning Execution Pipeline
(Preprocessing)
(Feature Extraction)
(Self-Attention)
(Loss Optimization)