def server(controller, config): """Serve the Prodigy REST API. controller (prodigy.core.Controller): The initialized controller. config (dict): Configuration settings, e.g. via a prodigy.json or recipe. """ global HUG_API set_controller(controller, config) from waitress.server import create_server if config.get('cors', True) is not False: HUG_API.http.add_middleware(CORSMiddleware(HUG_API)) port = os.getenv('PRODIGY_PORT', config.get('port', 8080)) host = os.getenv('PRODIGY_HOST', config.get('host', 'localhost')) server = create_server( __hug_wsgi__, port=port, host=host, # noqa: F821 channel_timeout=300, expose_tracebacks=True, threads=1) prints('Starting the web server at http://{}:{} ...'.format(host, port), 'Open the app in your browser and start annotating!') server.run() controller.save()
def __init__(self, nlp_ref, learner_ref, odqa_ref, dc_ref, coref_ref, userin_ref, reg_key, port_number, db_session_ref, dont_block=False): """Initialization method of :class:`dragonfire.api.Run` class This method starts an API server using :mod:`waitress` (*a pure-Python WSGI server*) on top of lightweight :mod:`hug` API framework. Args: nlp_ref: :mod:`spacy` model instance. learner_ref: :class:`dragonfire.learn.Learner` instance. odqa_ref: :class:`dragonfire.odqa.ODQA` instance. dc_ref: :class:`dragonfire.deepconv.DeepConversation` instance. userin_ref: :class:`dragonfire.utilities.TextToAction` instance. reg_key (str): Registration key of the API. port_number (int): Port number that the API will be served. db_session_ref: SQLAlchemy's :class:`DBSession()` instance. """ global __hug_wsgi__ # Fixes flake8 F821: Undefined name global nlp global learner global odqa global dc global coref global userin global server_reg_key global db_session nlp = nlp_ref # Load en_core_web_sm, English, 50 MB, default model learner = learner_ref odqa = odqa_ref dc = dc_ref coref = coref_ref userin = userin_ref server_reg_key = reg_key db_session = db_session_ref app = hug.API(__name__) app.http.output_format = hug.output_format.text app.http.add_middleware(CORSMiddleware(app)) self.waitress_thread = Thread(target=waitress.serve, args=(__hug_wsgi__, ), kwargs={"port": port_number}) if dont_block: self.waitress_thread.daemon = True self.waitress_thread.start() if not dont_block: self.waitress_thread.join()
def main(models=None, host='0.0.0.0', port=8080): if not models: models = ['en_core_web_sm'] else: models = [m.strip() for m in models.split(',')] for model in models: load_model(model) # Serving Hug API app = hug.API(__name__) app.http.add_middleware(CORSMiddleware(app)) waitress.serve(__hug_wsgi__, port=port)
def main(models=None, host='0.0.0.0', port=8080): if not models: models = ['en_core_web_sm'] else: models = [m.strip() for m in models.split(',')] for model in models: print("Loading model '{}'...".format(model)) MODELS[model] = spacy.load(model) # Serving Hug API app = hug.API(__name__) app.http.add_middleware(CORSMiddleware(app)) waitress.serve(__hug_wsgi__, port=port)
def __init__(self, nlpRef, userinRef, token): global nlp global omniscient global userin global dc global precomptoken nlp = nlpRef # Load en_core_web_sm, English, 50 MB, default model omniscient = Engine(nlp) dc = DeepConversation() userin = userinRef precomptoken = token app = hug.API(__name__) app.http.output_format = hug.output_format.text app.http.add_middleware(CORSMiddleware(app)) t = Thread(target=waitress.serve, args=(__hug_wsgi__, ), kwargs={"port": 3301}) t.start() t.join()
def __init__(self, nlp_ref, learner_ref, omniscient_ref, dc_ref, userin_ref, token, port_number): """Initialization method of :class:`dragonfire.api.Run` class This method starts an API server using :mod:`waitress` (*a pure-Python WSGI server*) on top of lightweight :mod:`hug` API framework. Args: nlp_ref: :mod:`spacy` model instance. learner_ref: :class:`dragonfire.learn.Learner` instance. omniscient_ref: :class:`dragonfire.omniscient.Omniscient` instance. dc_ref: :class:`dragonfire.deepconv.DeepConversation` instance. userin_ref: :class:`dragonfire.utilities.TextToAction` instance. token (str): API token. port_number (int): Port number that the API will be served. """ global nlp global learner global omniscient global dc global userin global precomptoken nlp = nlp_ref # Load en_core_web_sm, English, 50 MB, default model learner = learner_ref omniscient = omniscient_ref dc = dc_ref userin = userin_ref precomptoken = token app = hug.API(__name__) app.http.output_format = hug.output_format.text app.http.add_middleware(CORSMiddleware(app)) t = Thread(target=waitress.serve, args=(__hug_wsgi__, ), kwargs={"port": port_number}) t.start() t.join()
import hug import jwt from pymongo import MongoClient import redis import json from hug_middleware_cors import CORSMiddleware api = hug.API(__name__) api.http.add_middleware(CORSMiddleware(api)) client = MongoClient('localhost:27017') db = client.trustedauth @hug.get('/api/') def signup(): pass @hug.post('/api/aadhar') def aadhar(body): print(body) if(body['otp'] == '5431'): aadharId = body['aadharId'] print(aadharId) query = db.userdata.find_one({'aadharId': int(aadharId)}, {'_id': False}) print(query) return json.dumps(query) else: query = {'status' : 'Wrong OTP'} return json.dumps(query)
obj['punct'] = {} if token.is_quote: obj['punct']['type'] = 'quote' elif token.is_bracket: obj['punct']['type'] = 'bracket' else: obj['punct']['type'] = None if token.is_left_punct: if token.is_right_punct: obj['punct']["direction"] = "both" else: obj['punct']["direction"] = "left" elif token.is_right_punct: obj['punct']["direction"] = "right" else: obj['punct']["direction"] = None return obj if __name__ == '__main__': import waitress from hug_middleware_cors import CORSMiddleware app = hug.API(__name__) app.http.add_middleware(CORSMiddleware(app)) waitress.serve(__hug_wsgi__, port=8080)
def server(): if __name__ == "__main__": import waitress app = hug.API(__name__) app.http.add_middleware(CORSMiddleware(app)) waitress.serve(__hug_wsgi__, host='0.0.0.0', port=8190)
open_weather_api_key = api_keys["open_weather_api"] found = True break except Exception as e: last_exception = e if not found: logging.exception(last_exception) logging.info( "[Pre Server] Could not load API keys file or some keys are missing. Ensure keys.json exists in %s" % os.path.dirname(os.path.realpath(__file__))) sys.exit() api = hug.API(__name__) api.http.add_middleware(CORSMiddleware(api, allow_origins=ALLOWED_ORIGINS)) @hug.post('/autocomplete') def autocomplete(*args, **kwargs): current_input = kwargs.get("current_input") domain = 'maps.googleapis.com' path = 'maps/api/place/autocomplete/json' query = "input=%s&types=(cities)" % current_input url = "https://%s/%s?%s&key=%s" % (domain, path, query, google_places_api_key) result = requests.get(url) try: return format_autocomplete(json.loads(result.text)["predictions"])