def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): conf = "./yolov3-gurmina-brand.cfg" weights = "./yolov3-gurmina-brand_last.weights" names = "./gurmina-brand.names" # conf = "./yolov3-gurmina.cfg" # weights = "./yolov3-gurmina_best.weights" # names = "./gurmina.names" print(form.cleaned_data['detection']) print(form.cleaned_data['nms_threshold']) print(form.cleaned_data['conf_threshold']) print(form.cleaned_data['document']) obj = form.save() print(obj.document) a = detection("media/" + str(obj.document), conf, weights, names, float(form.cleaned_data['detection']), float(form.cleaned_data['nms_threshold']), float(form.cleaned_data['conf_threshold'])) return render( request, 'core/photo.html', { 'uploaded_file_url': obj.document.url, 'uploaded_file_name': obj.document.name, }) else: form = DocumentForm() form.fields['detection'].initial = 0.2 form.fields['nms_threshold'].initial = 0.1 form.fields['conf_threshold'].initial = 0.2 return render(request, 'core/model_form_upload.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) url = settings.MEDIA_URL + 'documents/' + request.FILES['document'].name url = url.encode('utf8') print(request.FILES, "======", type(request.FILES['document']), url.encode('utf8')) #(<MultiValueDict: {u'document': [<InMemoryUploadedFile: file_example_WAV_2MG.wav (audio/wav)>]}>, '======', <class 'django.core.files.uploadedfile.InMemoryUploadedFile'>, <type 'unicode'>) if form.is_valid(): write_xml.delay(url, request.FILES['document'].name) #print(form) #save_document_model.delay(url, request.FILES['document'].name) #handle_uploaded_file(request.FILES['file']) form.save() #return render(request, 'core/home.html', { 'urls': url }) return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid( ) and form.files['document'].content_type == 'text/plain': form.save() return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', {'form': form})
def upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() basic=info.objects.get(ph= request.session['userid']) documents = Document.objects.all() return render(request, 'index/home2.html', { 'documents': documents,'basic':basic }) else: form = DocumentForm() return render(request, 'index/home2.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', { 'form': form })
class TestFormImage(TestCase): def setUp(self): self.data = {} self.data['description'] = 'Tiny Image' self.files = {} self.files['document'] = SimpleUploadedFile('file.txt', b"file_content") self.files['image'] = SimpleUploadedFile('tiny.gif', TINY_GIF) self.form = DocumentForm(self.data, self.files) self.form.is_valid() def test_valid_form(self): self.assertEqual(True, self.form.is_valid()) def test_saved_document(self): self.assertEqual(self.files['document'], self.form.cleaned_data['document']) def test_saved_image(self): self.assertEqual(self.files['image'], self.form.cleaned_data['image'])
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): post = form.save(commit=False) post.owner = request.user post.save() return redirect('dashboard') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', { 'form': form })
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): instance = form.save(commit= False) instance.vendor_deal= request.user instance.save() return redirect('http://127.0.0.1:8000/') else: form = DocumentForm() return render(request, 'model_form_upload.html', { 'form': form })
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): document = form.save() # call to the new method csv = process_file(document.document) response = HttpResponse(csv, content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=result.csv' return response else: form = DocumentForm() return render(request, 'core/model_form_upload.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('home') else:# if request.method == 'GET': # If the form is submitted search_query = request.GET.get('search_box', None) form = DocumentForm() return render(request, 'core/model_form_upload.html', { 'form': form })
def json_to_xml(request): global document_form global doc_name_split if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() document_form = form.cleaned_data['document'] print(document_form) print("*******************") input_file = open("media/documents/{}".format(document_form), mode="r", encoding="utf-8") print(input_file) text = input_file.read() # print(text) print("uploaded test.json") #json to xml conversion xml_format = dicttoxml(loads(text), attr_type=False, root=False) clean_xml_format = xml_format.decode('utf-8') clean_xml_format = BeautifulSoup(xml_format.decode('utf-8'), "html.parser").prettify() print(clean_xml_format) print("%%%%%%%%%%%%%%%%%%%%%%%%%") #spliting the file_name if document_form: # doc_first_name = document_form.splitext('.')[0] doc_first_name = document_form.name doc_name_split = doc_first_name.split('.')[0] print(doc_name_split) output_file = open("media/documents/{}.xml".format(doc_name_split), "w", encoding="utf-8", errors="xmlcharrefreplace") output_file.write(clean_xml_format) print("created test.xml") # txt = view() key_dict = {'from': text} return render(request, 'core/json_to_xml.html', context=key_dict) # return redirect('md_to_html') else: form = DocumentForm() return render(request, 'core/json_to_xml.html', {'form': form})
def home(request): documents = Document.objects.all() if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() ds = pd.read_csv('./media/' + documents[0].document.name) viz = sns.heatmap(ds.corr()) fig = viz.get_figure() fig.savefig('./uploads/core/static/image/plot.png') documents.delete() return redirect('home') else: form = DocumentForm() return render(request, 'core/home.html', { 'documents': documents, 'form': form })
def md_to_html(request): global document_form global doc_name_split if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() document_form = form.cleaned_data['document'] print(document_form) input_file = open("media/documents/{}".format(document_form), mode="r", encoding="utf-8") print(input_file) text = input_file.read() # print(text) print("uploaded test.md") #markdown conversion html = markdown.markdown(text) #spliting the file_name if document_form: # doc_first_name = document_form.splitext('.')[0] doc_first_name = document_form.name doc_name_split = doc_first_name.split('.')[0] print(doc_name_split) output_file = open( "media/documents/{}.html".format(doc_name_split), "w", encoding="utf-8", errors="xmlcharrefreplace") output_file.write(html) print("created test.html") # txt = view() key_dict = {'from': text} return render(request, 'core/md_to_html.html', context=key_dict) # return redirect('md_to_html') else: form = DocumentForm() return render(request, 'core/md_to_html.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): fileName = time.strftime('%Y%m%d_%H%M%S') + '.' + request.FILES[ 'document'].name.split('.')[-1] request.FILES['document'].name = fileName DocumentForm(request.POST, request.FILES).save() os.makedirs(os.path.join(os.getcwd(), 'original_img', request.POST['location']), exist_ok=True) os.rename( os.path.join(os.getcwd(), 'original_img', fileName), os.path.join(os.getcwd(), 'original_img', request.POST['location'], fileName)) return redirect('home') else: form = DocumentForm() return render(request, 'core/model_form_upload.html', { 'form': form, 'documents': list(reversed(Document.objects.all()))[:10] })
def index(request): if request.method == 'POST' : if request.POST.get('userid',False): MyLoginForm = LoginForm(request.POST) if MyLoginForm.is_valid() and Cred.objects.filter(ph=request.POST['userid']).exists() : userid = MyLoginForm.cleaned_data['userid'] user=Cred.objects.get(ph= userid ) if user.active : if not user.reset: if user.signup_state == 4 : return render( request ,'index/checkpass.html', {'userid':userid}) return redirect('/signup') return redirect('/signup') return HttpResponse('your account have been deactivated.') return HttpResponse (' form cred validation failed') if request.POST.get('passwd',False): if Cred.objects.filter(ph=request.POST['id'], passw=request.POST['passwd']).exists(): request.session['userid']= request.POST['id'] basic=info.objects.get(ph= request.POST['id']) request.session['username']=basic.fname return render(request, 'index/home2.html', {'basic': basic }) return HttpResponse('password is wrong .') if request.FILES and request.POST: if 'username' in request.session : basic=info.objects.get(ph= request.session['userid']) form=DocumentForm(request.POST ,request.FILES) if form.is_valid(): form.save() documents = Document.objects.all() return render(request, 'index/home2.html', { 'documents': documents,'basic':basic }) return redirect('/') if request.method=='GET': if 'username' in request.session : basic=info.objects.get(ph= request.session['userid']) form = DocumentForm() return render(request ,'index/home2.html' ,{'form':form , "basic" :basic }) else : return render(request, 'index/index.html')
def xaml_to_csv(request): global document_form global doc_name_split if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() document_form = form.cleaned_data['document'] print(document_form) input_file = open("media/documents/{}".format(document_form), mode="r", encoding="utf-8") print(input_file) text = input_file.read() input_file.close() # print(text) print("uploaded test.md") #xml_to_csv conversion tree = ET.parse("media/documents/{}".format(document_form)) root = tree.getroot() #spliting the file_name if document_form: # doc_first_name = document_form.splitext('.')[0] doc_first_name = document_form.name doc_name_split = doc_first_name.split('.')[0] print(doc_name_split) # open a file for writing Resident_data = open( "media/documents/{}.csv".format(doc_name_split), 'w') # create the csv writer object csvwriter = csv.writer(Resident_data) resident_head = [] count = 0 for member in root.findall('Resident'): resident = [] address_list = [] if count == 0: name = member.find('Name').tag resident_head.append(name) PhoneNumber = member.find('PhoneNumber').tag resident_head.append(PhoneNumber) EmailAddress = member.find('EmailAddress').tag resident_head.append(EmailAddress) Address = member[3].tag resident_head.append(Address) csvwriter.writerow(resident_head) count = count + 1 name = member.find('Name').text resident.append(name) PhoneNumber = member.find('PhoneNumber').text resident.append(PhoneNumber) EmailAddress = member.find('EmailAddress').text resident.append(EmailAddress) Address = member[3][0].text address_list.append(Address) City = member[3][1].text address_list.append(City) StateCode = member[3][2].text address_list.append(StateCode) PostalCode = member[3][3].text address_list.append(PostalCode) resident.append(address_list) csvwriter.writerow(resident) Resident_data.close() #spliting the file_name # if document_form: # # doc_first_name = document_form.splitext('.')[0] # doc_first_name = document_form.name # doc_name_split = doc_first_name.split('.')[0] # print(doc_name_split) # output_file = open("media/documents/{}.csv".format(doc_name_split), "w", # encoding="utf-8", # errors="xmlcharrefreplace" # ) # output_file.write(html) print("created test.html") # txt = view() key_dict = {'from': text} return render(request, 'core/xaml_to_csv.html', context=key_dict) # return redirect('md_to_html') else: form = DocumentForm() return render(request, 'core/xaml_to_csv.html', {'form': form})
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): if os.path.exists("media"): print("exists") pass form.save() myfile = request.FILES['document'] query = request.POST['request'] sequenece = False if len(request.POST) == 2 else True print(sequenece) fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) uploaded_file_url = fs.url(filename) filename_base64 = subprocess.check_output("echo " + filename + " | base64 ", shell=True) filename_base64 = filename_base64[0:8].decode() print("name_base64 is ", filename_base64) # print(fs.url()) if sequenece: ''' ******************************************* change the command in the following line ******************************************* ''' command = "bash run_remote_multi.sh media/" + str( filename) + " \"" + str(query) + "\" media/" os.system(command) print(command) prefix = 1 while fs.exists( str(prefix) + "_inference_" + str(filename_base64) + ".jpg"): prefix += 1 print("prefix: ", prefix) with open("media/" + str(filename_base64) + '.json', 'r') as f: distros_dict = json.load(f) operations = distros_dict[0]['operations'] output_file_url_list = [] for index in range(1, prefix): name = operations[index - 1][0] if name == "color" or name == "tone": arg = "" else: arg = "{:.7f}".format(operations[index - 1][1][0]) url = fs.url( str(index) + "_inference_" + str(filename_base64) + ".jpg") op = str(name) + " " + arg print(op, url) output_file_url_list.append((op, url)) # output_file_url_list.append(fs.url(str(index)+"_inference_"+str(filename_base64)+".jpg")) print("Here are the results:") print(output_file_url_list) return render( request, 'core/model_form_upload.html', { 'query': query, 'show_sequenece': sequenece, 'uploaded_file_url': uploaded_file_url, 'output_file_url_list': output_file_url_list }) # print(fs.exists("1_inference_2_in.jpg")) command = "bash run_remote_single.sh media/" + str( filename) + " \"" + str( query) + "\" media/" + "inference_" + str(filename) print(command) os.system(command) output_file_url = fs.url("inference_" + str(filename)) # print(output_file_url) return render( request, 'core/model_form_upload.html', { 'query': query, 'show_sequenece': sequenece, 'uploaded_file_url': uploaded_file_url, 'output_file_url': output_file_url }) else: form = DocumentForm() return render(request, 'core/model_form_upload.html', {'form': form})