Example #1
0
    def suite_result(self, suite, result, **kwargs):
        """
        Extended from parent with JSON export functionality
        :param suite: default testrunner test suite
        :param result: StoreResultsTestRunner instance
        """
        result.results['results'] = self.get_results_summary(
            results=result.results)

        with open(settings.PROJECT_DIR('') + '/test_results.json',
                  'w') as outfile:
            json.dump(result.results, outfile, sort_keys=True, indent=4)

        t = get_template('test/test_results.html')
        c = Context(result.results)

        with open(settings.PROJECT_DIR('') + '/test_results.html',
                  'w') as outfile:
            outfile.write(t.render(c))

        super(ConcreteDiscoverRunner,
              self).suite_result(suite, result, **kwargs)
def download_pdf(data: pd.DataFrame, file_name='output'):
    data_html = data.to_html(index=False)
    try:
        data_pdf = pdf.from_string(data_html, False)
    except OSError:
        env = Environment(loader=FileSystemLoader(settings.PROJECT_DIR('templates')))
        template = env.get_template('pdf_export.html')
        template_vars = {"title": file_name.capitalize(),
                         "table": data_html}
        data_pdf = HTML(string=template.render(template_vars)).write_pdf()
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="{}.{}"'.format(file_name, 'pdf')
    response.write(data_pdf)
    return response
 def process_path(file_path, imf):
     if file_path:
         if file_path.startswith(settings.MEDIA_URL):
             file_path = file_path[1:]
         file_path = settings.PROJECT_DIR('../{0}'.format(file_path))
         files[field_name] = (imf.name, open(file_path, 'rb'))
Example #4
0
import numpy as np
import os
from muses.naive_classification.definitions_os import classes
from collections import OrderedDict
from keras.models import model_from_json
from PIL import Image
from django.conf import settings

LOADED_MODELS = {}

json_path = settings.PROJECT_DIR(
    os.path.join(
        '..',
        '..',
        '..',
        'src',
        'muses',
        'naive_classification',
        'model_architecture.json',
    ))


def predict_image_paths(image_paths, model_path, target_size=(128, 128)):
    """Use a trained classifier to predict the class probabilities of a list of images
    Returns most likely class and its probability

    :param image_paths: list of path(s) to the image(s)
    :param model_path: path to the pre-trained model
    :param target_size:
    :type image_paths: list
    :return: