<commit_before>from django.shortcuts import render
from django.views.generic import TemplateView
from django.http import HttpResponse

from forms import ApplicationForm
# Create your views here.

class IndexView(TemplateView):
    form_class = ApplicationForm
    template_name = 'index.html'

    def get(self, request):
        form = self.form_class(auto_id=False)
        return render(request, self.template_name, {'form': form})

    def post(self, request, *args, **kwargs):
         form = self.form_class(request.POST)<commit_msg>update post method<commit_after>import json
import cPickle as pickle

from django.shortcuts import render
from django.views.generic import TemplateView
from django.http import HttpResponse

from forms import ApplicationForm
# Create your views here.


class IndexView(TemplateView):
    form_class = ApplicationForm
    template_name = 'index.html'

    def get(self, request):
        form = self.form_class(auto_id=False)
        return render(request, self.template_name, {'form': form})

    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST)
        if form.is_valid():
            X = []
            X.append(str(form.cleaned_data['parents']))
            X.append(str(form.cleaned_data['has_nurs']))
            X.append(str(form.cleaned_data['form']))
            X.append(str(form.cleaned_data['children']))
            X.append(str(form.cleaned_data['housing']))
            X.append(str(form.cleaned_data['finance']))
            X.append(str(form.cleaned_data['social']))
            X.append(str(form.cleaned_data['health']))
            encoders = pickle.load(open('svm/pickles/encoders.pickle','r'))
            for i in range(0, len(X)):
                X[i] = encoders[i].transform([str(X[i])])[0]
            svm = pickle.load(open('svm/pickles/svm.pickle','r'))
            print X
            prediction = svm.predict(X)
            label = encoders[-1].inverse_transform(prediction)
            return HttpResponse(
                json.dumps({"prediction": label[0]}),
                content_type="application/json"
            )
        else:
            return HttpResponse(
                json.dumps(form.errors),
                content_type="application/json"
            )
{'fraction_non_alphanumeric': 0.12165129556433904, 'fraction_numerical': 0.001756697408871322, 'mean_word_length': 2.6801292407108237, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7167780', 'n_tokens_mistral': 671, 'n_tokens_neox': 656, 'n_words': 131}