From 0bad9c361f343e9abb09756909efe7eae649d0dd Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Tue, 28 Feb 2023 10:50:53 +0100 Subject: [PATCH] Update documentation --- README.md | 2 ++ app/main.py | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c0922d1..2a44eba 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ pip install -r models.txt (venv)$ uvicorn app.main:app --reload ``` +The server application is available on `http://localhost:8000`. To see the endpoint documentation, go to `http://localhost:8000/docs` + ## Troubleshooting for Mac users 2023-02-14: When running the app locally on a Mac, this error occured when calling the /models endpoint: diff --git a/app/main.py b/app/main.py index a84e64c..b1b2e8f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,5 @@ from fastapi import FastAPI, Response, status -from fastapi.responses import PlainTextResponse +from fastapi.responses import PlainTextResponse, HTMLResponse from app.internal.model_factory import * from vipscore_common.vips_model import VIPSModel from vipscore_common.entities import ModelConfiguration, Result @@ -24,9 +24,9 @@ app = FastAPI( ) # TODO Create a nice welcome page -@app.get("/") +@app.get("/", response_class=HTMLResponse) async def root(): - return {"message": "Hello World"} + return _welcome_html ####### Model listing endpoints ####### @@ -181,4 +181,20 @@ def _result_or_404(result, model_id:str, response:Response): return result else: response.status_code = status.HTTP_404_NOT_FOUND - return {"ERROR":"VIPS model with id=%s could not be found." % model_id} \ No newline at end of file + return {"ERROR":"VIPS model with id=%s could not be found." % model_id} + +_welcome_html = """ +<html> +<head> + <title>VIPSCore-Python</title> +</head> +<body> +<h1>VIPSCore-Python</h1> +<p>© 2023 <a href="https://nibio.no/en" target="new">NIBIO</a></p> +<p>Python implementation of VIPSCore, to enable models written in Python.</p> +<p><a href="docs/">Endpoints documentation</a></p> +<p><a href="https://gitlab.nibio.no/VIPS/VIPSCore-Python" target="new">Source code on NIBIO's GitLab</a></p> +<p><a href="https://gitlab.nibio.no/VIPS/documentation" target="new">VIPS technical documentation</a></p> +<p><a href="https://nibio.no/en/subjects/plant-health/vips--a-digital-pest-prediction-platform" target="new">Read more about VIPS</a></p> +</body> +""" \ No newline at end of file -- GitLab