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
80 from fiftyone_devicedetection_examples.example_utils
import ExampleUtils
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
88 class GettingStartedWeb():
91 def build(self, config, logger):
94 GettingStartedWeb.pipeline = PipelineBuilder().add_logger(logger).build_from_configuration(config)
99 GettingStartedWeb.app.run()
104 @app.route(
'/json', methods=[
'POST'])
108 flowdata = GettingStartedWeb.pipeline.create_flowdata()
113 flowdata.evidence.add_from_dict(webevidence(request))
121 return json.dumps(flowdata.jsonbundler.json)
130 flowdata = GettingStartedWeb.pipeline.create_flowdata()
135 flowdata.evidence.add_from_dict(webevidence(request))
141 response = make_response()
149 set_response_header(flowdata, response)
152 response.set_data(render_template(
176 configFile = Path(__file__).resolve().parent.joinpath(
"config.json").read_text()
177 config = json.loads(configFile)
179 dataFile = ExampleUtils.get_data_file_from_config(config)
180 foundDataFile =
False 182 raise Exception(
"A data file must be specified in the config.json file.")
186 elif os.path.isabs(dataFile) ==
False:
187 newPath = ExampleUtils.find_file(dataFile)
190 ExampleUtils.set_data_file_in_config(config, newPath)
193 foundDataFile = os.path.exists(dataFile)
195 if foundDataFile ==
False:
196 raise Exception(
"Failed to find a device detection data file matching " +
197 f
"'{dataFile}'. If using the lite file, then make sure the " +
198 "device-detection-data submodule has been updated by running " +
199 "`git submodule update --recursive`. Otherwise, ensure that the filename " +
200 "is correct in config.json.")
206 logger = Logger(min_level=
"info")
208 config = GettingStartedWeb.build_config()
210 GettingStartedWeb().build(config, logger).run()
212 if __name__ ==
"__main__":