How to use django rest api to do inference?
I was trying to build a website with Django rest API as the backend. when given a string Its gives the score from 1 to 10 for negativity.
The frontend part of the website was built using next.js. Previously I have made the same app without Django rest API by doing all inference in the views.py file. Now I am using Rest API I am confused about where should I need to include the machine learning inference code.
I have seen tutorials on the internet showing that inference code is attached in the models.py file. Previously when I included inference code in views.py the page used to get reload whenever I do the inference. I want to avoid it. What is the best practice to include inference code while using Django rest API.

I do it the following way:
from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['GET', 'POST'])
def snippet_list(request):
    &quot;&quot;&quot;
    List all code snippets, or create a new snippet.
    &quot;&quot;&quot;
    if request.method == 'GET':
        # if you have a GET request data do stuffs here, else remove get

    elif request.method == 'POST':
        data = request.data
        # run your inference code here and get the predictions
        context = {
           'score': score
        }
        return Response(context , status=status.HTTP_200_OK)

