Home > database >  How to deploy a machine learning model in a django web app?
How to deploy a machine learning model in a django web app?

Time:05-21

My project is the conception and realization of a web application for the detection of ransomwares based on machine learning. For the realization, I made a web application with python, Django, HTML and CSS. On the other hand i have to create a machine learning code that makes the detection of these ransomware viruses.

Now what I have to do is deploy the machine learning code in my web app. I'll explain a little how it works, the user first registers and then he chooses a csv file to scan, he uploads it and then he chooses the machine learning model he wants use and then he clicks on scan, when he clicks on scan the file will be scanned by the model he has chosen and a result will be returned to him which is either 1: the file is a ransomware or 0: it is not a ransomware. So, I built the web app, I built the model Now my problem is how to pass user input to the model And than take the model's out put to the user.

Need help please.

CodePudding user response:

Basically you are going to create a view like this.

def do_some_prediction_view(request,id):
    categories = Categorie.objects.exclude(name="Customized Tshirts")
    if request.method == 'POST':
        form_tshirt_size = ShirtSize(request.POST)
        if form_tshirt_size.is_valid():
            weight=form_tshirt_size.cleaned_data['weight']
            height=form_tshirt_size.cleaned_data['height']
            age=form_tshirt_size.cleaned_data['age']
            y_pr = pd.DataFrame(np.array([[weight, height, age]]),
                        columns=['weight', 'height', 'age'])
            prediction = model.predict(y_pr)[0] - 1
            return JsonResponse(classes[prediction],safe=False)
        else:
            return JsonResponse({'status':'error'})

CodePudding user response:

I've managed to do something like this using a deep learning model. It's fairly simple everything you're doing in python can be done in the django project you just have to create views and forms to handle the user data input. So you're either new to django or want the whole code snippets ?

  • Related