Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪵 Log #2

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "FastCLAM: FastAPI for CLAMS",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}/fastclam",
"module": "poetry",
"args": ["run", "uvicorn", "app:app", "--reload"],
"jinja": true,
"justMyCode": false
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "FastCLAM: FastAPI for CLAMS",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "poetry",
"args": [
"run",
"uvicorn",
"fastclam.app:app",
"--reload",
"--host",
"0.0.0.0",
"--log-level",
"debug"
],
"jinja": false,
"justMyCode": false
}
]
}
26 changes: 18 additions & 8 deletions fastclam/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from pydantic import BaseModel
from typing import List
import requests
from os import path, environ
from datetime import datetime
from .log import log
from .version import __VERSION__
from xml.etree import ElementTree


class Inputs(BaseModel):
Expand All @@ -28,23 +28,33 @@ def home() -> dict:

@app.post('/source')
def generate_source(files: Inputs) -> dict:
"""Generate a new source MMIF"""
"""Generate a new source MMIF from multiple input files"""
log.info(f'sourcing media {files.files}')
mmif = generate_source_mmif(files.files)
json_value = loads(str(mmif))
log.debug(f'sourced: {json_value}')
return json_value


@app.post('/pipeline')
def run_pipeline(pipeline: Pipeline) -> list:
def run_pipeline(pipeline: Pipeline, all: bool = False) -> list:
"""Run a list of media through a list of apps"""
results = []
log.info(f'Starting pipeline {pipeline}')
for media in pipeline.files:
mmif = generate_source(Inputs(files=[media]))
results.append(mmif)
print('have source', mmif)

for app in pipeline.apps:
log.debug(f'Running {media} through {app}')
response = requests.post(app, json=mmif)
assert response.status_code == 200, f'Error with {pipeline}: {response}'
mmif = response.json()
try:
mmif = response.json()
except Exception as e:
log.warn(f'Error parsing json {e}')
log.debug('Trying to parse as xml')
mmif = ElementTree.fromstring(response.content)
results.append(mmif)
print('results: ', results)

log.info(f'Ran {len(pipeline.files)} files through {len(pipeline.apps)} apps')
return results
11 changes: 11 additions & 0 deletions fastclam/log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from loguru import logger as log
from rich.logging import RichHandler

log.configure(
handlers=[
{
"sink": RichHandler(),
"format": "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
}
]
)
Loading