Skip to content

Commit

Permalink
Adds /run for single clams-app run (#11)
Browse files Browse the repository at this point in the history
## Usage
`curl -v http://localhost:8000/run?url=localhost:5000 -H 'Content-Type:application/json' [email protected]`
  • Loading branch information
mrharpo authored Jul 6, 2023
1 parent 9ea57de commit 4991b7d
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions fastclam/app.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from json import loads
from json.decoder import JSONDecodeError
from xml.etree import ElementTree
from xml.etree.ElementTree import ParseError

import requests
from clams.source import generate_source_mmif
from fastapi import FastAPI, HTTPException
from fastapi.responses import PlainTextResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from clams.source import generate_source_mmif
from json import loads
import requests

from .log import log
from .models import Inputs, Pipeline
from .version import __VERSION__
from xml.etree import ElementTree
from xml.etree.ElementTree import ParseError
from json.decoder import JSONDecodeError


class MMIFException(HTTPException):
pass


app = FastAPI()
app = FastAPI(title='FastCLAM')


Expand All @@ -41,6 +42,23 @@ def generate_source(files: Inputs) -> dict:
return json_value


@app.post('/run')
def run_app(url: str, mmif: dict) -> dict:
"""Run a single app with a single MMIF"""
log.info(f'Running {url}')
response = requests.post('http://' + url, json=mmif)
log.debug(f'received response {response.status_code}, {response.headers}')
if response.status_code != 200:
log.debug(response.content)
raise HTTPException(
status_code=response.status_code,
detail=response.content,
)
results = response.json()
log.success(f'{url} Success!')
return results


@app.post('/pipeline')
def run_pipeline(pipeline: Pipeline) -> list | dict | str:
"""Run a list of media through a list of apps
Expand Down

0 comments on commit 4991b7d

Please sign in to comment.