first
commit
2919a5b7ef
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for HelloWorld project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HelloWorld.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@ -0,0 +1,129 @@
|
||||
"""
|
||||
Django settings for HelloWorld project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.0.1.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure--+*8fgp(cj%9+t103%ou46vjjv+fe$&y5q$h77axpfi*_=^)tu'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
ALLOW_UPLOAD = ['jpg', 'png', 'jpeg']
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = ''
|
||||
STATICFILES_DIRS = ( os.path.join('static'), )
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'learn',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'HelloWorld.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'HelloWorld.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
@ -0,0 +1,9 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path, register_converter, re_path
|
||||
from learn import views
|
||||
|
||||
urlpatterns = [
|
||||
path('upload/', views.upload), # 上传图片
|
||||
path('dlurl/', views.dlurl), # 上传图片
|
||||
path('',views.home),
|
||||
]
|
||||
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for HelloWorld project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HelloWorld.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class LearnConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'learn'
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #eee;border-left-width:6px;background-color:#FAFAFA;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:40px;line-height:40px;border-bottom:1px solid #eee}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 10px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view .layui-code-ol li:first-child{padding-top:10px}.layui-code-view .layui-code-ol li:last-child{padding-bottom:10px}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}.layui-code-demo .layui-code{visibility:visible!important;margin:-15px;border-top:none;border-right:none;border-bottom:none}.layui-code-demo .layui-tab-content{padding:15px;border-top:none}
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 701 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 299 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -0,0 +1,55 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
import os
|
||||
from datetime import datetime
|
||||
import learn.yolov5.detect as DL
|
||||
from pathlib import PosixPath
|
||||
import requests, os, json
|
||||
|
||||
def upload(request):
|
||||
if request.method == 'POST':
|
||||
file = request.FILES.get('file') #获取前端上传的文件
|
||||
print("************")
|
||||
print(file)
|
||||
print("************")
|
||||
fix = datetime.now().strftime('%Y%m%d%H%M%S%f')+'1' #给文件加前缀防止文件名重复
|
||||
#以下用绝对路径存储文件,之前我用相对路径一直写不对
|
||||
curPath = os.path.abspath( os.path.dirname( __file__ ) )
|
||||
img_path = os.path.abspath(curPath+'/static/upload/'+fix+file.name)
|
||||
#返回给前端的图片路径用相对路径,前端用绝对路径反而加载不了图片
|
||||
img_path_res = '/static/detected/'+fix+file.name
|
||||
print(img_path)
|
||||
f = open(img_path,'wb')
|
||||
for i in file.chunks():
|
||||
f.write(i)
|
||||
f.close()
|
||||
RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected"))
|
||||
res = 1
|
||||
if(res == 1):
|
||||
return JsonResponse({'img_name':img_path_res,'code':RR})
|
||||
else:
|
||||
return JsonResponse({'img_name':img_path_res,'code':RR})
|
||||
|
||||
def dlurl(request):
|
||||
if request.method == 'GET':
|
||||
url = request.GET["url"] #获取前端上传的文件
|
||||
print(url)
|
||||
name = url.split(r'/')[-1]
|
||||
if not (name.endswith(".jpg") or name.endswith(".jpeg") or name.endswith(".png") or name.endswith(".bmp")):
|
||||
return JsonResponse({'flag': False})
|
||||
|
||||
fix = datetime.now().strftime('%Y%m%d%H%M%S%f')+'1' #给文件加前缀防止文件名重复
|
||||
curPath = os.path.abspath( os.path.dirname( __file__ ) )
|
||||
img_path = os.path.abspath(curPath+'/static/download/'+fix+name)
|
||||
r = requests.get(url)
|
||||
# 保存
|
||||
with open (img_path, 'wb') as f:
|
||||
f.write(r.content)
|
||||
f.close
|
||||
#返回给前端的图片路径用相对路径,前端用绝对路径反而加载不了图片
|
||||
img_path_res = '/static/detected/'+fix+name
|
||||
RR = DL.run(weights=(curPath+"/yolov5/v6m6.pt"), source=img_path, project=(curPath+"/static/detected"))
|
||||
return JsonResponse({'img_name':img_path_res,'code':RR, 'flag': True})
|
||||
|
||||
def home(request):
|
||||
return render(request, 'home.html')
|
||||
@ -0,0 +1 @@
|
||||
Subproject commit db920e09e3becdf7496b9f0a520e02b94c79cf67
|
||||
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HelloWorld.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -0,0 +1,56 @@
|
||||
absl-py==1.0.0
|
||||
asgiref==3.5.0
|
||||
backports.zoneinfo==0.2.1
|
||||
cachetools==4.2.4
|
||||
certifi==2021.5.30
|
||||
charset-normalizer==2.0.10
|
||||
cycler==0.11.0
|
||||
Cython==0.29.26
|
||||
Django==4.0.1
|
||||
flatbuffers==2.0
|
||||
fonttools==4.28.5
|
||||
google-auth==2.3.3
|
||||
google-auth-oauthlib==0.4.6
|
||||
grpcio==1.43.0
|
||||
idna==3.3
|
||||
importlib-metadata==4.10.0
|
||||
kiwisolver==1.3.2
|
||||
Markdown==3.3.6
|
||||
matplotlib==3.5.1
|
||||
numpy==1.21.1
|
||||
oauthlib==3.1.1
|
||||
onnx==1.10.2
|
||||
onnx-simplifier==0.3.6
|
||||
onnxoptimizer==0.2.6
|
||||
onnxruntime==1.10.0
|
||||
onnxruntime-gpu==1.10.0
|
||||
opencv-python==4.5.5.62
|
||||
packaging==21.3
|
||||
pandas==1.3.5
|
||||
Pillow==8.3.1
|
||||
protobuf==3.19.1
|
||||
pyasn1==0.4.8
|
||||
pyasn1-modules==0.2.8
|
||||
pyparsing==3.0.6
|
||||
python-dateutil==2.8.2
|
||||
pytz==2021.3
|
||||
PyYAML==6.0
|
||||
requests==2.27.1
|
||||
requests-oauthlib==1.3.0
|
||||
rsa==4.8
|
||||
scipy==1.7.3
|
||||
seaborn==0.11.2
|
||||
six==1.16.0
|
||||
sqlparse==0.4.2
|
||||
tensorboard==2.7.0
|
||||
tensorboard-data-server==0.6.1
|
||||
tensorboard-plugin-wit==1.8.1
|
||||
thop==0.0.31.post2005241907
|
||||
torch==1.9.0+cu111
|
||||
torchaudio==0.9.0
|
||||
torchvision==0.10.0+cu111
|
||||
tqdm==4.62.3
|
||||
typing-extensions==3.10.0.0
|
||||
urllib3==1.26.7
|
||||
Werkzeug==2.0.2
|
||||
zipp==3.7.0
|
||||
Loading…
Reference in New Issue