smitathkr1 commited on
Commit
eb0bd77
·
verified ·
1 Parent(s): 9a79395

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -394,9 +394,19 @@ with st.sidebar:
394
  functions=molecule_custom_functions,
395
  function_call='auto'
396
  )
397
- data = json.loads(response_functions.choices[0].message.function_call.arguments)
 
 
 
 
 
 
 
 
 
 
398
  if data:
399
- molecule_name = data['molecule_name']
400
  if molecule_name:
401
  response = requests.get(f"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{molecule_name}/cids/TXT")
402
  cid = response.text
 
394
  functions=molecule_custom_functions,
395
  function_call='auto'
396
  )
397
+ try:
398
+ arguments = response_functions.choices[0].message.function_call.arguments
399
+ if arguments is not None:
400
+ data = json.loads(arguments)
401
+ else:
402
+ data = {} # or set to None or a default value as needed
403
+ except (IndexError, KeyError, TypeError) as e:
404
+ #print(f"Error accessing the data: {e}")
405
+ data = {}
406
+
407
+ #data = json.loads(response_functions.choices[0].message.function_call.arguments)
408
  if data:
409
+ molecule_name = data['molecule_name','']
410
  if molecule_name:
411
  response = requests.get(f"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{molecule_name}/cids/TXT")
412
  cid = response.text