This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
78 from pathlib
import Path
81 from flask.helpers
import make_response
82 from flask
import Flask, request, render_template
83 from fiftyone_pipeline_core.logger
import Logger
84 from fiftyone_pipeline_core.pipelinebuilder
import PipelineBuilder
85 from fiftyone_pipeline_core.web
import webevidence, set_response_header
88 class GettingStartedWeb():
91 def build(self, config, logger):
94 GettingStartedWeb.pipeline = PipelineBuilder().add_logger(logger).build_from_configuration(config)
99 GettingStartedWeb.app.run()
105 @app.route(
'/json', methods=[
'POST'])
109 flowdata = GettingStartedWeb.pipeline.create_flowdata()
114 flowdata.evidence.add_from_dict(webevidence(request))
122 return json.dumps(flowdata.jsonbundler.json)
132 flowdata = GettingStartedWeb.pipeline.create_flowdata()
137 flowdata.evidence.add_from_dict(webevidence(request))
143 response = make_response()
151 set_response_header(flowdata, response)
154 response.set_data(render_template(
178 configFile = Path(__file__).resolve().parent.joinpath(
"config.json").read_text()
179 config = json.loads(configFile)
181 dataFile = ExampleUtils.get_data_file_from_config(config)
182 foundDataFile =
False 184 raise Exception(
"A data file must be specified in the config.json file.")
188 elif os.path.isabs(dataFile) ==
False:
189 newPath = ExampleUtils.find_file(dataFile)
192 ExampleUtils.set_data_file_in_config(config, newPath)
195 foundDataFile = os.path.exists(dataFile)
197 if foundDataFile ==
False:
198 raise Exception(
"Failed to find a device detection data file matching " +
199 f
"'{dataFile}'. If using the lite file, then make sure the " +
200 "device-detection-data submodule has been updated by running " +
201 "`git submodule update --recursive`. Otherwise, ensure that the filename " +
202 "is correct in config.json.")
208 logger = Logger(min_level=
"info")
210 config = GettingStartedWeb.build_config()
212 GettingStartedWeb().
build(config, logger).
run()
214 if __name__ ==
"__main__":