Skip to content
Snippets Groups Projects
Commit cbaa0ea6 authored by dw927's avatar dw927
Browse files

Merge branch 'dwelsh' into 'main'

Connected test_report_provider to fake_model. API now returns proper structure...

See merge request !3
parents 66d7d957 a50fb79e
Branches
No related tags found
1 merge request!3Connected test_report_provider to fake_model. API now returns proper structure...
venv/
__pycache__
.vscode/
\ No newline at end of file
from flask import Flask, render_template, url_for, flash, redirect
from flask import jsonify
from flask import request
from flask import Flask, render_template, url_for, flash, redirect, request
import requests
import urllib.request
import os
......@@ -10,20 +8,37 @@ from werkzeug.utils import secure_filename
app = Flask(__name__)
UPLOAD_FOLDER = 'static/uploads/'
REPORTS_SERVICE_URL = 'http://127.0.0.1:5000'
app.secret_key = "secret key"
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024 * 1000 * 20 # 20 GB
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif', 'tif'])
BASE_URL = 'dpath'
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
@app.route(f'/{BASE_URL}/')
def home():
return render_template('home.html')
@app.route(f'/{BASE_URL}/term2')
def term2():
reports = requests.get(f'{REPORTS_SERVICE_URL}/dpath/report').json()
return render_template('2ndTerm.html', reports=reports)
@app.route(f'/{BASE_URL}/reports')
def reports():
reports = requests.get(f'{REPORTS_SERVICE_URL}/dpath/report').json()
return render_template('reports.html', reports=reports)
@app.route('/', methods=['GET', "POST"])
def upload_image():
if 'file' not in request.files:
......@@ -43,7 +58,12 @@ def upload_image():
flash('Allowed image types are - png, jpg, jpeg, gif, tif')
return redirect(request.url)
@app.route('/display/<filename>')
def display_image(filename):
# print('display_image filename: ' + filename)
return redirect(url_for('static', filename='uploads/' + filename), code=301)
if __name__ == "__main__":
app.run(debug=True)
\ No newline at end of file
body {
width: 100%;
}
.container {
width: 100%;
text-align: center;
}
.report-table {
width: 90%;
padding: 20px;
}
th {
padding: 5px;
background-color: lightskyblue;
}
tr:hover {
background-color: lightgray;
}
td {
padding-left: 5px;
padding-right: 5px;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
\ No newline at end of file
front_end/static/uploads/reportImage1244.png

90.5 KiB

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Slide Analyzer</title>
{% include 'includes/stylesload.html' %}
</head>
{% include 'includes/navbar.html' %}
<div class="progress w-50">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-label="Animated striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar"
aria-label="Animated striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%">
</div>
</div>
{% if filename %}
......
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Digital Pathology</a>
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="./reports">Reports</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">New Report</a>
</li>
</ul>
</nav>
\ No newline at end of file
{% block content %}
<h1>{% block title %} Reports {% endblock %}</h1>
<table class="report-table">
<th class="left">Id</th>
<th class="left">Status</th>
<th class="right">Run Date</th>
{% for report in reports %}
<tr>
<td class="left">{{ report.id }}</td>
<td class="left">Completed</td>
<td class="right">{{ report.report.runDate }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
\ No newline at end of file
{% block content %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link href="{{ url_for('static', filename='styles/style.css') }}" rel="stylesheet">
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Reports</title>
{% include 'includes/stylesload.html' %}
</head>
<body>
{% include 'includes/navbar.html' %}
<div class="container">
{% include 'includes/reports.html' %}
</div>
</body>
\ No newline at end of file
from flask import Flask
from flask import jsonify
from flask import request
from flask import render_template
from s3_provider import Provider as provider
# from s3_provider import Provider
from test_report_provider import Provider
from fake_model import LearningModel as Model
import uuid
......@@ -18,21 +18,25 @@ VALID_EXTENSIONS = [
PREFIX = 'dpath'
@app.route(f'/{PREFIX}/')
def home():
return render_template('home.html')
@app.route(f'/{PREFIX}/report/<int:report_id>')
@app.route(f'/{PREFIX}/report/<int:report_id>', methods=['GET'])
def get_report(report_id) :
provider = Provider()
return jsonify(provider.get_report(report_id))
@app.route(f'/{PREFIX}/report', methods=['GET'])
def get_reports() :
provider = Provider()
response = jsonify(provider.get_reports())
response.status_code = 200
return response
@app.route(f'/{PREFIX}/report/image', methods=['POST'])
def upload_image():
response = validate_request(request)
if response.status_code == 400:
return response
provider = provider()
provider = Provider()
id = uuid.uuid1()
provider.save_binary(request.files['file'], id)
response = jsonify(Model(id).start())
......
from faker import Faker
import uuid
from fake_model import LearningModel
fake = Faker()
def create_report(s3_path):
report = {
class Provider:
def get_reports(self) :
i = 0
reports = []
while(i < 10):
reports.append(self.create_report(""))
i += 1
return reports
def create_report(self, s3_path):
id = uuid.uuid1()
report = LearningModel(id).start()
return {
"id": id,
"matchRate" : 75.89,
"status": "Running",
"runDate": fake.date_between(start_date='-30d', end_date='today')
"report": report
}
def get_report(self, id):
report = self.create_report("")
report.id = id
return report
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment