Skip to content

Commit

Permalink
Merge pull request #2 from stanfordnmbl/update-latest
Browse files Browse the repository at this point in the history
Upgrade to version 1.1.
  • Loading branch information
AlbertoCasasOrtiz authored Jul 10, 2024
2 parents 13a9030 + 99ad40f commit 7ed90dd
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ stop:
start:
docker-compose up -d
# -v $(pwd)/.env:/code/.env
docker run --name motionlab_openpose --link motionlab_redis_1:redis --link motionlab_www_1:www --net motionlab_default -d --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 stanfordnmbl/motionlab-worker /bin/sh -c 'celery -A worker worker --loglevel=info --concurrency=1 --pool=solo'
docker run --name motionlab_openpose --link motionlab_redis_1:redis --link motionlab_www_1:www --net motionlab_default -d --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 stanfordnmbl/motionlab-worker /bin/sh -c 'celery -A worker worker --loglevel=debug --concurrency=1 --pool=solo'

run: docker stop start
4 changes: 3 additions & 1 deletion motionlab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
def get_file_path(directory):
def func(instance, filename):
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
name = os.path.basename(filename).split('.')[0]
name = name.replace(' ', '_')
filename = "%s-%s.%s" % (name, uuid.uuid4(), ext)
return os.path.join(directory, filename)
return func

Expand Down
31 changes: 31 additions & 0 deletions motionlab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@
},
]

# LOGS.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '[DJANGO] %(levelname)s %(asctime)s %(module)s '
'%(name)s.%(funcName)s:%(lineno)s: %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'motionlab-log.log', # Specify the path to the log file
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'default',
}
},
'loggers': {
'django': {
'handlers': ['file', 'console'], # Add the 'console' handler here
'level': 'DEBUG',
'propagate': False,
},
},
}

# Max file size.
# Set FILE_UPLOAD_MAX_MEMORY_SIZE to 1 GB
FILE_UPLOAD_MAX_MEMORY_SIZE = 1 * 1024 * 1024 * 1024 # 51 GB
Expand Down
47 changes: 39 additions & 8 deletions motionlab/templates/motionlab/analysis.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
{% extends "motionlab/base.html" %}
{% load static %}
{% load static custom_filters %}
{% block content %}

{% get_media_prefix as MEDIA_URL %}

<style>
.console {
background-color: #000;
color: #0f0;
padding: 10px;
font-family: monospace;
white-space: pre-wrap; /* Ensures long lines are wrapped */
border: 1px solid #444;
border-radius: 4px;
}
</style>

<script>
var video_name = "{{ video_name|safe }}";

function copyToClipboard() {
/* Get the text field */
var copyText = document.getElementById("link");
Expand All @@ -18,6 +32,8 @@

/* Alert the copied text */
alert("The results link " + copyText.value + "is now copied.\nSave it in a safe place to get access to your results.");

console.log(video_name)
}
</script>

Expand Down Expand Up @@ -76,7 +92,11 @@ <h3 class="section-heading">
<h3>Original video</h3>
<div class="video-container" style="margin-bottom: 2em; height: 20em;">
<video controls style="width: 100%; height: 100%" autoplay loop muted>
<source src="{{ video.file.url }}" type="video/mp4">
{% if video and video.file and video.file.url %}
<source src="{{ video.file.url }}" type="video/mp4">
{% else %}
<p>File URL does not exist.</p>
{% endif %}
Your browser does not support the video tag.
</video>
</div>
Expand All @@ -86,7 +106,11 @@ <h3>Motion Analysis</h3>
<div class="video-container" style="margin-bottom: 2em; height: 20em;">
{% if annotation.status == "done" or annotation.status == "error" %}
<video controls style="width: 100%; height: 100%" autoplay loop muted>
<source src="{{ annotation.file.url }}" type="video/mp4">
{% if annotation and annotation.file and annotation.file.url %}
<source src="{{ annotation.file.url }}" type="video/mp4">
{% else %}
<p>File URL does not exist.</p>
{% endif %}
Your browser does not support the video tag.
</video>
{% else %}
Expand Down Expand Up @@ -132,15 +156,22 @@ <h3>Motion Analysis</h3>
{% if annotation.status == "done" or annotation.status == "error" %}
<div class="section categories" id="analyze" style="padding: 6rem 0 6rem;">
<div class="container">
<h3 class="section-heading">
{% if annotation.status == "processing" or annotation.status == "submitted" %}
The video is still processing, please visit this site later.
<h3 class="section-heading">The video is still processing, please visit this site later.</h3>
{% elif annotation.status == "error" %}
Processing finished with an error, we are investigating it.
</br>
<div>
{% for key, value in results.items %}
{% with parts=value|split:":" %}
<h3 class="section-heading">{{ parts.0 }}:</h3>
<div class="console">{{ parts.1|unquote_error }}</div>
{% endwith %}
{% endfor %}
</div>
{% else %}
Results
<h3 class="section-heading">Results</h3>
{% endif %}
</h3>

{% if annotation.status == "done" %}
<div style="text-align: center">
<table style="margin-left:auto; margin-right:auto;">
Expand Down
22 changes: 21 additions & 1 deletion motionlab/templates/motionlab/analysis_multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

{% get_media_prefix as MEDIA_URL %}

<style>
.console {
background-color: #000;
color: #0f0;
padding: 10px;
font-family: monospace;
white-space: pre-wrap; /* Ensures long lines are wrapped */
border: 1px solid #444;
border-radius: 4px;
}
</style>

<script>

var video_file_urls = JSON.parse("{{ video_file_urls|escapejs }}");
Expand Down Expand Up @@ -83,7 +95,15 @@
textToShow += ` <div class="container">`
textToShow += ` <h3 class="section-heading">`
if (annotation_statuses[selectedValue] == "error") {
textToShow += ` Processing finished with an error, we are investigating it.`
for (let key in results_list[selectedValue]) {
var parts = results_list[selectedValue][key].split(":")
textToShow += `<h3 class="section-heading">`
textToShow += parts[0]
textToShow += `:</h3>`
textToShow += `<div class="console">`
textToShow += decodeURIComponent(parts[1])
textToShow += `</div>`
}
} else {
textToShow += ` Results`
}
Expand Down
1 change: 0 additions & 1 deletion motionlab/templates/motionlab/for_researchers.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ <h3 class="section-heading" style="text-align: center; padding: 1em 0;">Open-sou


<script>
{{ recordid }}
document.getElementById("id_file").onchange = function() {
document.getElementById("videoForm").submit();
document.getElementById("id_file").disabled = true;
Expand Down
10 changes: 9 additions & 1 deletion motionlab/templatetags/custom_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import template

import urllib.parse
import json

register = template.Library()
Expand Down Expand Up @@ -38,3 +38,11 @@ def num_processed(annotation_statuses):
@register.filter(name='zip')
def zip_lists(a, b):
return zip(a, b)

@register.filter
def split(value, arg):
return value.split(arg)

@register.filter
def unquote_error(value):
return urllib.parse.unquote(value)
Loading

0 comments on commit 7ed90dd

Please sign in to comment.