def __init__(self, api_model, api_version, app_id, app_key, disable_groups=False): # Represent user data self.user_profile = self.UserProfile() self.actual_diagnosis = infermedica_api.Diagnosis(sex="", age=0) self.actual_diagnosis.set_extras(attribute="disable_groups", value=disable_groups) self.triage = None # Infermedica API configuration infermedica_api.configure(app_id=app_id, app_key=app_key, model=api_model, api_version=api_version) try: self.infermedica_api = infermedica_api.get_api() except MissingConfiguration as e: # TODO: esta excepcion no esta funcionando logger.critical(str(e)) raise Exception
def main(): infermedica_api.configure({ 'app_id': args.id, 'app_key': args.key, 'dev_mode': args.mode, }) api = infermedica_api.get_api()
def generateQuestions(kid, choice_id): infermedica_api.configure(app_id='182669ec', app_key='65fbdbdf4f285711553f6bc6d94d9e53') api = infermedica_api.get_api() #UserDetails request = infermedica_api.Diagnosis(sex='male', age=35) for k in range(len(kid)): request.add_symptom(kid[k], choice_id[k]) #print(kid[k], choice_id[k]) request = api.diagnosis(request) try: flag=request.conditions[0]["probability"] except: flag=1 print("Elixir: This sounds critical. You may want to consult a doctor instead.") return while(flag<0.20): print("Elixir: "+request.question.text) prev_out = request.conditions[0]['name'] #print(request.conditions) entities = request.question.items #print(entities) # for i in range(len(entities)): # print(entities[i]["id"]) # print(entities[i]["name"]) print("Elixir: "+entities[0]["name"]+"?") new_input = raw_input("Elixir: Enter your Choice"+"(Yes/No/Maybe/DontAsk): ") new_input = new_input.lower() if(new_input=="yes"): request.add_symptom(entities[0]["id"], "present") elif(new_input=="no"): request.add_symptom(entities[0]["id"], "absent") elif(new_input=="maybe"): request.add_symptom(entities[0]["id"], "unknown") else: break request = api.diagnosis(request) try: flag=request.conditions[0]["probability"] except: flag=1 disease = prev_out print("Elixir: You may have "+disease) external_page = wikipedia.page(disease) print("Elixir: External URL(For more info): "+external_page.url) return disease = request.conditions[0]['name'] print("Elixir: You may have "+disease) external_page = wikipedia.page(disease) print(wikipedia.summary(disease, sentences=1)) print("Elixir: External URL(For more info): "+external_page.url)
def infermedicaCon(self): """ Instantiate Infermedica API """ infermedica_api.configure({ 'app_id': '143fb87b', 'app_key': '7c3c9dd9c4adcdc0d9c314007c28441f', 'dev_mode': True # Use only during development on production remove this parameter }) return infermedica_api.get_api(), infermedica_api
def get_instance(): parser = ConfigParser() # create a config parser parser.read('configurations.ini') #reading configuration file aId = parser.get('auth', 'app_id') aKey = parser.get('auth', 'app_key') infermedica_api.configure( app_id=aId, app_key=aKey) # configure our api to authenticate requests api = infermedica_api.get_api() return api
def __init__(self, sex, age): infermedica_api.configure({ 'app_id': INF_APP_ID, 'app_key': INF_APP_KEY, 'dev_mode': True # Use only during development on production remove this parameter }) self.inf_api = infermedica_api.get_api() self.sex = sex self.age = age self.symptoms = {} self.last_question = None self.condition = None
def testing(): infermedica_api.configure(app_id='eb66ec4d', app_key='0dd627685ea5a3453973ea6aab7f36c1') api = infermedica_api.get_api() symtoms = ["heart", "headache", "craving"] # Create diagnosis object with initial patient information. # Note that time argument is optional here as well as in the add_symptom function request = infermedica_api.Diagnosis(sex='male', age=35) for i in symtoms: symptom_id = api.search(i)[0]["id"] print(symptom_id) request.add_symptom(symptom_id, 'present') # # request.add_symptom('s_21', 'present') # request.add_symptom('s_98', 'present') # request.add_symptom('s_107', 'absent') # request.set_pursued_conditions(['c_33', 'c_49']) # Optional # call diagnosis request = api.diagnosis(request) # # Access question asked by API # print(request.question) # print(request.question.text) # actual text of the question # print(request.question.items) # list of related evidences with possible answers # print(request.question.items[0]['id']) # print(request.question.items[0]['name']) # print(request.question.items[0]['choices']) # list of possible answers # print(request.question.items[0]['choices'][0]['id']) # answer id # print(request.question.items[0]['choices'][0]['label']) # answer label # Access list of conditions with probabilities # print(request.conditions) # print(request.conditions[0]['id']) print(request.conditions[0]['name']) # print(request.conditions[0]['probability']) # Next update the request and get next question: # Just example, the id and answer shall be taken from the real user answer request.add_symptom(request.question.items[0]['id'], request.question.items[0]['choices'][1]['id']) # call diagnosis method again request = api.diagnosis(request) # ... and so on, until you decide to stop the diagnostic interview. return request.conditions[0]['name']
def setup_examples(): """ Setup environment to easily run examples. API credentials need to be provided here in order to set up api object correctly. """ try: import infermedica_api except ImportError: import sys sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) import infermedica_api # !!! SET YOUR CREDENTIALS AS ENVIRONMENTAL VARIABLES "APP_ID" & "APP_KEY" OR SET THEM HERE !!! app_id = os.getenv("APP_ID", "YOUR_APP_ID") app_key = os.getenv("APP_KEY", "YOUR_APP_KEY") # Prepare API v3 connector as default one infermedica_api.configure( **{ "app_id": app_id, "app_key": app_key, "dev_mode": True, # Use only during development or testing/staging, on production remove this parameter }) # Prepare API v2 connector under 'v2' alias infermedica_api.configure( **{ "alias": "v2", "api_connector": "ModelAPIv2Connector", "app_id": app_id, "app_key": app_key, "dev_mode": True, # Use only during development or testing/staging, on production remove this parameter }) # enable logging of requests and responses http.client.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True
def getQuestion(sex_input, age_input, symptoms_list): infermedica_api.configure(app_id='cf82ff04', app_key='e4ea29fdc3b01d4263da84423dc6cac0') api = infermedica_api.get_api() symptoms = symptoms_list #CATCH TRUE SYMPTOMS request = infermedica_api.Diagnosis(sex=sex_input, age=age_input) #CATCH for i in symptoms: json_symptoms = "{ \"text\": \"" + i + "\", \"include_tokens\": \"false\"}" print(json_symptoms) try: symptom_id = parse2(json_symptoms).json()["mentions"][0]["id"] request.add_symptom(symptom_id, 'present') except IndexError: pass request = api.diagnosis(request) rest_of_test(api, request) return request.question #question du resultat
def setup_examples(): """ Setup environment to easily run examples. API credentials needs to be provided here in order to set up api object correctly. """ try: import infermedica_api except ImportError: import sys import os sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import infermedica_api # !!! ENTER YOUR CREDENTIALS HERE !!! infermedica_api.configure({ 'app_id': 'YOUR_APP_ID', 'app_key': 'YOUR_APP_KEY', 'dev_mode': True # Use only during development on production remove this parameter }) import logging # enable logging of requests and responses try: import httplib httplib.HTTPConnection.debuglevel = 1 except ImportError: import http.client http.client.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True
def setup_examples(): """ Setup environment to easily run examples. API credentials needs to be provided here in order to set up api object correctly. """ try: import infermedica_api except ImportError: import sys import os sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import infermedica_api # !!! ENTER YOUR CREDENTIALS HERE !!! infermedica_api.configure({ 'app_id': '0e59ae9e', 'app_key': '65e0fa7cedd4a2a3344b0654b55498f5' }) import logging # enable logging of requests and responses try: import httplib httplib.HTTPConnection.debuglevel = 1 except ImportError: import http.client http.client.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True
def get_conditions(self, sex, age, symptoms): ''' Return a list of possible conditions by the symptoms :param sex: string can only be "female" or "male" :param age: int :param symptoms: list of strings list of symptoms :rtype: list of strings list of possible conditions ''' infermedica_api.configure(app_id='2f25564c', app_key='bf70a95520b458fe0e69974f34d19a22') api = infermedica_api.get_api() # Create diagnosis object with initial patient information. request = infermedica_api.Diagnosis(sex=sex, age=age) for i in range(len(symptoms)): if symptoms[i] is None: continue try: request.add_symptom(symptoms[i], 'present') except: x = 0 try: request = api.diagnosis(request) except: y = 0 result = [] # get list of possible conditions for i in range(min(len(request.conditions), 3)): try: result.append(request.conditions[i]['name']) except: x = 0 return result
def setup_examples(): """ Setup environment to easily run examples. API credentials needs to be provided here in order to set up api object correctly. """ try: import infermedica_api except ImportError: import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import infermedica_api # !!! ENTER YOUR CREDENTIALS HERE !!! infermedica_api.configure({ 'app_id': 'YOUR_APP_ID', 'app_key': 'YOUR_APP_KEY', 'dev_mode': True # Use only during development on production remove this parameter }) import logging # enable logging of requests and responses try: import httplib httplib.HTTPConnection.debuglevel = 1 except ImportError: import http.client http.client.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True
def setup_examples(): """ Setup environment to easily run examples. API credentials needs to be provided here in order to set up api object correctly. """ try: import infermedica_api except ImportError: import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import infermedica_api # !!! ENTER YOUR CREDENTIALS HERE !!! infermedica_api.configure({ 'app_id': '0e59ae9e', 'app_key': '65e0fa7cedd4a2a3344b0654b55498f5' }) import logging # enable logging of requests and responses try: import httplib httplib.HTTPConnection.debuglevel = 1 except ImportError: import http.client http.client.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True
# import gae_fix # import pyrebase # firebase = pyrebase.initialize_app({ # "apiKey": FIREBASE_API_KEY, # "authDomain": FIREBASE_AUTH_DOMAIN, # "databaseURL": FIREBASE_DB_URL, # "storageBucket": FIREBASE_STORAGE_BUCKET # }) # db = firebase.database() app = Flask(__name__) app.config['DEBUG'] = True infermedica_api.configure(app_id=INF_APP_ID, app_key=INF_APP_KEY) sessionMap = {} inf_api = infermedica_api.get_api() conditions = inf_api.conditions_list() @app.route('/webhook', methods=['POST']) def webhook(): req = request.get_json(silent=True, force=True) print("Request:") print(json.dumps(req, indent=4)) res = processRequest(req)
import infermedica_api infermedica_api.configure(app_id='Your App Id', app_key='App Key') class medget: api = infermedica_api.get_api() def get_data(self,sex_m,age_m): ''' Initialize the user to be diagnosed ''' self.user_data = infermedica_api.Diagnosis(sex=sex_m.lower(), age=age_m) def add_symptoms(self, ids): ''' The ids is the list of dicts with keys 'id' and 'status' ''' for i in ids: self.user_data.add_symptom( str(i[str(u'id')]), str(i[str(u'status')]) ) def search_symptoms(self, symptoms_str): ''' Outputs more symptoms related to symptom_str (is a list of symptoms) user enters ''' search_res = [] for i in symptoms_str: res = self.api.search(i)
import infermedica_api from medget import medget infermedica_api.configure(app_id='349a2f56', app_key='cca4f464530bc1b49433057c2470fd44') request = medget() request.get_data('male', 12) request.add_symptoms([ { 'id': 's_21', 'status': 'present' }, { 'id': 's_98', 'status': 'present' }, { 'id': 's_107', 'status': 'present' }, ]) a = request.get_question() #print(a) '''for i in a: print(i['choices']) print(i['id']) print(i['name']) ''' print(request.get_result())
from __future__ import print_function import infermedica_api infermedica_api.configure(app_id='eb4835a9', app_key='679dd699e25f6bee7fe14cc3dc4d2b99') api = infermedica_api.get_api() def get_diagnosis(age, sex): ''' this function gets the symptoms from the user and adds them to search in infermedica ''' request = infermedica_api.Diagnosis(sex=sex, age=age) flag = True print ('Please enter the various symptoms you have line by line.') print ('Press enter once more when you are done entering all of your symptoms.') print ('The more symptoms you enter the more accurate our diagnosis would be.') while (flag): symptom=raw_input('') if(symptom==""): flag = False break dic = api.search(symptom) try: SID = dic[0]['id'] request.add_symptom(SID, 'present') except: print("") request = api.diagnosis(request) return request.conditions[0]['name'], request.conditions[0]['probability']
import infermedica_api infermedica_api.configure(app_id='38004d4f', app_key='f0d2cfeac82933b5b67a656e8ba46eb0') class medget: api = infermedica_api.get_api() def get_data(self, sex_m, age_m): self.user_data = infermedica_api.Diagnosis(sex=sex_m, age=age_m) def add_symptoms(self, ids): for i in ids: self.user_data.add_symptom(str(i[str(u'id')]), str(i[str(u'status')])) #absent status add def search_symptoms(self, symptoms_str): search_res = [] #global api #j=0 for i in symptoms_str: res = self.api.search(i) #j = 0 for k in res: res_p = {}
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dict_of_rec = { "about_treatment":"Lifestyle and home remedies" ,"overveiw": "Overview" ,"causes": "Causes" ,"prevention": "Prevention","about_symptoms": "Symptoms"} last_intent = tracker.latest_message['intent'].get('name').split(".")[-1] parent_intent = tracker.latest_message['intent'].get('name').split(".")[0] disease = tracker.get_slot("disease") print(last_intent) print(parent_intent) intent = tracker.latest_message['intent'].get('name') print(intent) shan_text = [ { "recipient_id": "bot", "type":"text", "text": "Hi again!" } ] shan_btn = [ { "recipient_id": "bot", "type":"button", "buttons": [ { "title": "about products", "payload": "about products" }, { "title": "founders of Medsamaan", "payload": "founders of Medsamaan" }, { "title": "about Medsamaan", "payload": "about Medsamaan" } ] } ] shan_img = [ { "recipient_id": "bot", "type":"image", "images": [ { "text": "about products", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" } ] } ] shan_img_btn =[ { "recipient_id": "bot", "type" : "image_button", "buttons": [ { "title": "about products", "payload": "about products" }, { "title": "founders of Medsamaan", "payload": "founders of Medsamaan" }, { "title": "about Medsamaan", "payload": "about Medsamaan" } ], "images": [ { "text": "about products", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" }, { "text": "founders of Medsamaan", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" }, { "text": "about Medsamaan", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" } ] } ] shan_img_btn_txt =[ { "recipient_id": "bot", "type" : "image_button_text", "text":"cnocvowecowlcwwobvnw wobwevc nwocwe wowbveviosecewv obfnweof vwovnw vwowf eofefne fefoefqefqefqefoaeflaefne faeoffb ofef", "buttons": [ { "title": "about products", "payload": "about products" }, { "title": "founders of Medsamaan", "payload": "founders of Medsamaan" }, { "title": "about Medsamaan", "payload": "about Medsamaan" } ], "images": [ { "text": "about products", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" }, { "text": "founders of Medsamaan", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" }, { "text": "about Medsamaan", "src": "https://www.drugs.com/mayo/media/ADF419FD-A51A-430C-9C92-5703D91A2733.jpg" } ] } ] dict_of_rec = { "about_treatment":"Lifestyle and home remedies" ,"overveiw": "Overview" ,"causes": "Causes" ,"prevention": "Prevention","about_symptoms": "Symptoms"} disease = tracker.get_slot("disease") intent = tracker.latest_message['intent'].get('name') print(intent) if intent == "shantanu_img": dispatcher.utter_custom_json(shan_img) elif intent == "shantanu_text": dispatcher.utter_custom_json(shan_text) elif intent == "shantanu_btn": dispatcher.utter_custom_json(shan_btn) elif intent == "shantanu_img_btn": dispatcher.utter_custom_json(shan_img_btn) elif intent == "shantanu_text_img_button": dispatcher.utter_custom_json(shan_img_btn_txt) elif parent_intent == "smalltalk": wks = ms_sm_wks cell = wks.find(last_intent) ## row & col of search element answer = wks.cell(cell.row, cell.col+3).value ## dispatched answer dispatcher.utter_message(answer) shan_text = [ { "recipient_id": "bot", "type":"text", "text": answer } ] dispatcher.utter_custom_json(shan_text) elif intent =="prevention": wks = disease_symptom_overview print(disease) cell = wks.find(disease.capitalize()) ## row & col of search element answer = wks.cell(cell.row, cell.col+4).value #list_of_rem = list(dict_of_rec.keys()).remove(intent) list_of_rem = list(dict_of_rec.keys()) list_of_rem.remove(intent) # dispatcher.utter_message("Overview for " + disease) # dispatcher.utter_message(answer) shan_text = [ { "recipient_id": "bot", "type":"text", "text": answer } ] dispatcher.utter_custom_json(shan_text) list_of_buttons = [] for i in list_of_rem: temp_dict ={} temp_dict['title'] = disease +" of "+ dict_of_rec[i] temp_dict['payload'] = i +" of "+ disease list_of_buttons.append(temp_dict) shan_text_btn = [ { "recipient_id": "bot", "type":"text_button", "text":"Related Topics to Look For:", "buttons": list_of_buttons } ] dispatcher.utter_custom_json(shan_text_btn) elif intent=="about_treatment": wks = disease_symptom_overview cell = wks.find(disease.capitalize()) ## row & col of search element answer = wks.cell(cell.row, cell.col+1).value # dispatcher.utter_message("Treatment for " + disease) # dispatcher.utter_message(answer) list_of_rem = list(dict_of_rec.keys()) list_of_rem.remove(intent) shan_text = [ { "recipient_id": "bot", "type":"text", "text": answer } ] dispatcher.utter_custom_json(shan_text) list_of_buttons = [] for i in list_of_rem: temp_dict ={} temp_dict['title'] = disease +" of "+ dict_of_rec[i] temp_dict['payload'] = i +" of "+ disease list_of_buttons.append(temp_dict) shan_text_btn = [ { "recipient_id": "bot", "type":"text_button", "text":"Related Topics to Look For:", "buttons": list_of_buttons } ] dispatcher.utter_custom_json(shan_text_btn) elif intent=="prevention": wks = disease_symptom_overview cell = wks.find(disease.capitalize()) ## row & col of search element answer = wks.cell(cell.row, cell.col+4).value #list_of_rem = list(dict_of_rec.keys()).remove(intent) list_of_rem = list(dict_of_rec.keys()) list_of_rem.remove(intent) # dispatcher.utter_message("Overview for " + disease) # dispatcher.utter_message(answer) shan_text = [ { "recipient_id": "bot", "type":"text", "text": answer } ] dispatcher.utter_custom_json(shan_text) list_of_buttons = [] for i in list_of_rem: temp_dict ={} temp_dict['title'] = disease +" of "+ dict_of_rec[i] temp_dict['payload'] = i +" of "+ disease list_of_buttons.append(temp_dict) shan_text_btn = [ { "recipient_id": "bot", "type":"text_button", "text":"Related Topics to Look For:", "buttons": list_of_buttons } ] dispatcher.utter_custom_json(shan_text_btn) elif intent=="about_symptoms": wks = disease_symptom_overview cell = wks.find(disease.capitalize()) ## row & col of search element answer = wks.cell(cell.row, cell.col+5).value #list_of_rem = list(dict_of_rec.keys()).remove(intent) list_of_rem = list(dict_of_rec.keys()) list_of_rem.remove(intent) # dispatcher.utter_message("Symptoms for " + disease) # dispatcher.utter_message(answer) shan_text = [ { "recipient_id": "bot", "type":"text", "text": answer } ] dispatcher.utter_custom_json(shan_text) list_of_buttons = [] print(list_of_rem) for i in list_of_rem: temp_dict ={} temp_dict['title'] = disease +" of "+ dict_of_rec[i] temp_dict['payload'] = i +" of "+ disease list_of_buttons.append(temp_dict) shan_text_btn = [ { "recipient_id": "bot", "type":"text_button", "text":"Related Topics to Look For:", "buttons": list_of_buttons } ] dispatcher.utter_custom_json(shan_text_btn) elif intent=="overview": wks = disease_symptom_overview cell = wks.find(disease.capitalize()) ## row & col of search element answer = wks.cell(cell.row, cell.col+2).value #list_of_rem = list(dict_of_rec.keys()).remove(intent) list_of_rem = list(dict_of_rec.keys()) list_of_rem.remove(intent) # dispatcher.utter_message("Overview for " + disease) # dispatcher.utter_message(answer) shan_text = [ { "recipient_id": "bot", "type":"text", "text": answer } ] dispatcher.utter_custom_json(shan_text) list_of_buttons = [] for i in list_of_rem: temp_dict ={} temp_dict['title'] = disease +" of "+ dict_of_rec[i] temp_dict['payload'] = i +" of "+ disease list_of_buttons.append(temp_dict) shan_text_btn = [ { "recipient_id": "bot", "type":"text_button", "text":"Related Topics to Look For:", "buttons": list_of_buttons } ] dispatcher.utter_custom_json(shan_text_btn) elif intent=="symptom_checker": user_uttered_msg = tracker.latest_message["text"] infermedica_api.configure(app_id='d91c00d6',app_key='50573fae6348390c63e87e7c5b584547') api = infermedica_api.get_api() headers = { 'App-Id': 'd91c00d6', 'App-Key': '50573fae6348390c63e87e7c5b584547', 'Content-Type': 'application/json', } data = str({"text":user_uttered_msg}) response = requests.post('https://api.infermedica.com/v2/parse', headers=headers, data=data) response.text request = infermedica_api.Diagnosis(sex='male', age=30) syms = response.json()['mentions'] for i in syms: request.add_symptom(i['id'], i['choice_id']) print(request) # call diagnosis request = api.diagnosis(request) request = request.condition for i in request: shan_text = [ { "recipient_id": "bot", "type":"text", "text": i['common_name']+": "+str(i['probability']) } ] dispatcher.utter_custom_json(shan_text) elif "locate" in intent: url='https://maps.googleapis.com/maps/api/place/textsearch/json?'# where you will send your requests api_key='' #enter your api key generated, if not generated then generate at https://cloud.google.com/maps-platform/?apis=places url2 = 'https://maps.googleapis.com/maps/api/place/details/json?' def maps(search,location): x = [] i =0 while((x == [] or x==None) and i<10): x=requests.get(url+'query={}&key={}'.format(search.lower()+"+"+"in"+"+"+location.lower(),api_key)).json()['results'] i+=1 #Extracted 'results' out of the api data . 'results' would come in json #return(x) if len(x)<1: print("No "+search.lower()+" found at {0}".format(location)) # if query invalid then prompt the user to be more general else: RANGE=3 # default 3 results would be displayed . Change accordingly if len(x)<3:RANGE=2 if len(x)<2:RANGE=1 print("nearest ".format(RANGE) + search.lower() + " locations found at {} :\n".format(location)) for i in range(RANGE): y = None j = 0 while((y==[] or y=={} or y==None) and j<10): y = requests.get(url2+'place_id={}&key={}'.format(x[i]['place_id'],api_key)).json()#['formatted_phone_number']#["formatted_phone_number"] j+=1 if 'result' in y: shan_text = [ { "recipient_id": "bot", "type":"name_descript", "items": [{"name":x[i]['name'], "descript":x[i]['formatted_address']+"\n"+y['result']['formatted_phone_number']+"\n"+"https://www.google.com/maps/place/?q=place_id:"+x[i]['place_id']}] } ] else: shan_text = [ { "recipient_id": "bot", "type":"name_descript", "items": [{"name":x[i]['name'], "descript":x[i]['formatted_address']+"\n"+"https://www.google.com/maps/place/?q=place_id:"+x[i]['place_id']}] } ] dispatcher.utter_custom_json(shan_text) loc = tracker.get_slot('current_location') if intent=="locate_clinic": maps("hospital",loc) elif intent=="locate_doctor": maps("doctor",loc) "text": i['common_name']+":"+i['probability'] } ]
import os, requests from watson_developer_cloud import ConversationV1, LanguageTranslatorV2 from flask import Flask, jsonify, json, request, render_template import infermedica_api infermedica_api.configure(app_id='8eab6cb8', app_key='ff87a9caf26433944a6236f19e70173f') conversation = ConversationV1( username= '******', password= '******', version= '2017-05-26' ) workspace_id = '957755fd-3d4c-4b76-854e-92154d6887d0' language_translator = LanguageTranslatorV2( url= "https://gateway.watsonplatform.net/language-translator/api", username= "******", password= "******" ) app = Flask(__name__) global context context = {} @app.route('/') def Welcome(): return app.send_static_file('webpage.html') @app.route('/conversation', methods=['GET', 'POST'])
from rest_framework.decorators import api_view, permission_classes from rest_framework.permissions import AllowAny from rest_framework.status import (HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND, HTTP_200_OK) from rest_framework.response import Response from rest_framework.views import APIView from django.contrib.auth import authenticate from .models import Nutrient, Record, Symptomrecord, Diseaserecord, Foodrecord, Foodlist, Selfcarediary from .serializers import NutrientsSerializer from rest_framework.views import APIView from rest_framework import permissions, status import infermedica_api # import Symp from .serializers import SelfcarediarySerializer import requests, json infermedica_api.configure(app_id='945555e1', app_key='be2ee424c225c567086a084637a359de') def home(request): if request.user.is_authenticated(): return render(request, 'drug/home.html', {}) return redirect('accounts/login') def loginpage(request): return render(request, 'drug/login.html', {}) def search(symptom): api = infermedica_api.get_api() data = api.search(symptom["orth"])
import json from flask import Flask, request, make_response, jsonify import requests from string import Template import infermedica_api import os infermedica_app_id = os.getenv("infermedica_app_id") infermedica_app_key = os.getenv("infermedica_app_key") infermedica_api.configure({ 'app_id': infermedica_app_id, 'app_key': infermedica_app_key, 'dev_mode': True }) app = Flask(__name__) log = app.logger options_dict = { "yes": "present", "no": "absent", "dontknow": "unknown", } image_url = { "present": "https://cdn2.iconfinder.com/data/icons/check-mark-style-1/1052/check_mark_voting_yes_no_24-512.png", "absent": "https://cdn2.iconfinder.com/data/icons/check-mark-style-1/1052/check_mark_voting_yes_no_13-512.png", "unknown": "https://www.pngfind.com/pngs/m/81-815205_question-face-blinking-emoji-emoji-angry-png-transparent.png",
from django.http import HttpResponse, HttpResponseRedirect from django.urls import reverse from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic import TemplateView from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth import login from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.forms import UserCreationForm from django.forms.models import model_to_dict from django import forms from .forms import SearchForm, SymptomsForm, PatientForm, RecordForm, TrackerForm from .models import Search, Symptoms, Patient, Tracker import infermedica_api infermedica_api.configure(app_id='dd7d8ffc', app_key='805d0529637017534b6b5726f942c5b9') class TrackerUpdate(LoginRequiredMixin, UpdateView): model = Tracker fields = ['tracker_name', 'label1', 'label2', 'label3'] class TrackerDelete(LoginRequiredMixin, DeleteView): model = Tracker success_url = '/trackers/' class SymptomsDelete(LoginRequiredMixin, DeleteView): model = Symptoms success_url = '/patients/lookup/'
import infermedica_api infermedica_api.configure(app_id='841be15b', app_key='69d5e76a396ce3681070d53d364c7f7c') api = infermedica_api.get_api()
import infermedica_api, sys, json, ast infermedica_api.configure(app_id='bc057cc8', app_key='cb1d56dafc45383462d1bcbe754c9033') possible_conditions = [] def read_in_from_server(): lines = sys.stdin.readlines()[0] lines = json.loads(lines) return (lines) def read_in_from_terminal(text): lines = input(text) return lines.split(",") def convert_to_json(request): r = {} r['case_id'] = request.case_id r['conditions'] = [c for c in request.conditions] r['evaluation_time'] = request.evaluation_time r['extras'] = request.extras r['extras_permanent'] = request.extras_permanent r['lab_tests'] = request.lab_tests r['patient_age'] = request.patient_age r['patient_sex'] = request.patient_sex r['pursued'] = request.pursued r['question'] = {} r['question']['extras'] = request.question.extras
from django.http import HttpResponse from django.shortcuts import render import infermedica_api from django.http import HttpResponseRedirect infermedica_api.configure(app_id='945555e1', app_key='be2ee424c225c567086a084637a359de') def index(request): api = infermedica_api.get_api() template = 'causes/index.html' response = HttpResponse("<h1>This is the causes page") debug = request.session['name'] print(request.session['name']) print("we have this many:", len(debug)) cause = infermedica_api.Diagnosis(sex='female', age=35) for x in range(0, len(debug)): cause.add_symptom(debug[x], 'present') cause = api.diagnosis(cause) first_cause=cause.conditions[0]['name'] second_cause=cause.conditions[1]['name'] third_cause=cause.conditions[2]['name'] first_prob=cause.conditions[0]['probability'] second_prob=cause.conditions[1]['probability'] third_prob=cause.conditions[2]['probability']
import infermedica_api infermedica_api.configure(app_id='5298366e', app_key='386b8464a0b2f2e2aea0598cb64b7c96') api = infermedica_api.get_api() response = api.parse() mentions = response.mentions request = infermedica_api.Diagnosis(sex='male', age=35) for i in mentions: request.add_symptom(i.id, i.choice_id) response = api.diagnosis(request) symptom_list = [] k = 0 for i in response.conditions: k += 1 p = {} p = {'id': i['id'], 'name': i['name'], 'probablity': i['probability']} symptom_list.append(p) if (k == 2): break print(symptom_list) # call diagnosis # request = api.diagnosis(request)