-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
70 lines (64 loc) · 2.48 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from classification import *
from django.contrib import messages
from pathlib import Path
from django.core.files.storage import FileSystemStorage
import pandas as pd
from recommendation import *
# Create your views here.
def classify(request):
if request.method == 'POST':
description = request.POST['input']
print("user input")
print(description)
result = pipe_clf.predict([str(description)])[0]
if result == 1:
messages.success(request, "requested task is automatable")
else:
messages.success(request, "requested task is non automatable")
return render(request, 'ideation/index.html')
else:
print("came inside")
return render(request, 'ideation/index.html')
def dumpclassify(request):
print("inside dumpclassify")
if request.method == 'POST':
#print(request.FILES)
myfile = request.FILES['myfile']
fs = FileSystemStorage('media/classify','media/classify')
filename = fs.save(myfile.name, myfile)
#print(Path(filename).suffix)
if Path(filename).suffix == '.csv' and 'ideationinputs' in Path(filename).stem:
uploaded_file_url = fs.url(filename)
test=pd.read_csv(fs.path(filename),encoding='latin')
#print(test.columns)
#print(fs.path(filename))
result = pipe_clf.predict(test['TASK'])
total_result = list(result)
print(total_result.count(1))
context ={
'automatable' : total_result.count(1),
'nonautomatable': total_result.count(-1),
'total': len(total_result)
}
return render(request, 'ideation/index.html',context)
else:
messages.error(request, "please upload csv file")
else:
print("came inside")
return render(request, 'ideation/index.html')
def recommending(request):
if request.method == 'POST':
iptext = request.POST['dropdown']
print(iptext)
print(recommend)
recommendations = recommend(iptext)
print(recommendations)
context ={
'recommendations': recommendations,
'text':iptext
}
return render(request, 'ideation/index.html',context)
else:
return render(request, 'ideation/index.html')