PKٳMmvishwakarma/__init__.py# -*- coding: utf-8 -*- """ __init__.py ~~~~~~~~~~~ no description available :copyright: (c) 2018 by Diagram AI. :license: see LICENSE for more details. """ __title__ = 'vishwakarma' __version__ = '0.0.2' __author__ = 'diagram-ai' from .pgmplot import pgmplot PKMvishwakarma/pgmplot.py# -*- coding: utf-8 -*- '''Build visualization for a pgmpy model Example: Attributes: Todo: ''' import pgmpy import jsonpickle import requests import tempfile import os import string from datetime import datetime from IPython.display import Image def pgmplot(obj, width=600): '''Build visualization for a pgmpy model Args: obj (pgmpy.models): The pgmpy model that needs to be visualized width (int): Width of the image in px (default 600) Returns: Image: The image that can be displayed inline in a Jupyter notebook ''' # list of supported classes supp_classes = (pgmpy.models.BayesianModel, pgmpy.models.NaiveBayes, pgmpy.models.MarkovModel, pgmpy.models.FactorGraph, pgmpy.models.DynamicBayesianNetwork) if isinstance(obj, supp_classes): tmp_dir_name = '' try: # get json representation of the object frozen_pgm = jsonpickle.encode(obj) # create a temp directory & temp file tmp_dir_name = tempfile.mkdtemp() # generate a tmp file name (excluding file extension) epoch = datetime.datetime.now().strftime('%s') tmp_file_name = ''.join( [random.choice(string.ascii_letters + string.digits) for n in range(8)]) tmp_file_name = os.path.join( tmp_dir_name, tmp_file_name + epoch + '.png') url = 'http://www.diagram.ai/api/vishwakarma/pgmplot' resp = requests.get(url, data=frozen_pgm) if(resp.ok): # get the image file and write it to temp dir if resp.headers.get('Content-Disposition'): open(tmp_file_name, 'wb').write(resp.content) # now return this image as an Image object displayable in # the jupyter notebook return Image(filename=tmp_file_name, width=width) else: raise Exception(resp.raise_for_status()) finally: # cleanup the temp directory shutil.rmtree(tmp_dir_name, ignore_errors=True) else: raise TypeError('Expected pgmpy modely; unsupported object type: ' + type(obj)) PKf7M|X++#vishwakarma-0.0.2.dist-info/LICENSEMIT License Copyright (c) 2018 Diagram AI Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!Hd BUc!vishwakarma-0.0.2.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!H+6$vishwakarma-0.0.2.dist-info/METADATAUMO0 F\i;ƭ'M}Ipk5J܍I%JyKP0 ؚZN3kT(cF߳aS׫W)qXGq!ϲ銴:k:A/$"z[?WjIc}K?LRBX|KՌBI̗L2z=$A=5m1>0E뷐a✷'ro#¦m􅅹Q<ܴoXq3ܞYU[a"hqp~,p /]%TZm=)PK!H1*"vishwakarma-0.0.2.dist-info/RECORD}͖BP}ςo1 %ԕ)o7~VӪ 9٣ʖiZE\;1$π(}iGO\gVڽmVwUy^'m<,FDŽߺZeӿm