NihalGazi commited on
Commit
156d641
·
verified ·
1 Parent(s): ed6efa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -42,15 +42,20 @@ def generate_reaction_steps(reactants, products):
42
 
43
  chat_session = model.start_chat(history=[])
44
  response = chat_session.send_message(prompt)
45
- print(response)
46
- # Extract the JSON output
47
  try:
48
- steps = json.loads(response.text)
49
- except json.JSONDecodeError:
 
 
 
 
50
  steps = {"error": "Failed to decode JSON from Gemini response."}
51
 
52
  return steps
53
 
 
54
  # Gradio interface
55
  def process_reaction(reactants, products):
56
  steps = generate_reaction_steps(reactants, products)
 
42
 
43
  chat_session = model.start_chat(history=[])
44
  response = chat_session.send_message(prompt)
45
+
46
+ # Extract the JSON content from the response
47
  try:
48
+ # Parsing the raw response to extract the JSON text
49
+ content = response.result["candidates"][0]["content"]["parts"][0]["text"]
50
+
51
+ # Loading the JSON string to a Python dictionary
52
+ steps = json.loads(content)
53
+ except (json.JSONDecodeError, KeyError):
54
  steps = {"error": "Failed to decode JSON from Gemini response."}
55
 
56
  return steps
57
 
58
+
59
  # Gradio interface
60
  def process_reaction(reactants, products):
61
  steps = generate_reaction_steps(reactants, products)