NihalGazi commited on
Commit
2a32308
·
verified ·
1 Parent(s): 7636eb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -14
app.py CHANGED
@@ -21,8 +21,8 @@ model = genai.GenerativeModel(
21
  generation_config=generation_config,
22
  )
23
 
24
- # Function to generate substeps recursively
25
- def generate_substeps(reactants, products):
26
  prompt = f"Given reactants: {reactants} and products: {products}, break down the reaction mechanism into simple steps and provide in JSON format."
27
 
28
  chat_session = model.start_chat(history=[])
@@ -34,21 +34,11 @@ def generate_substeps(reactants, products):
34
  except json.JSONDecodeError:
35
  steps = {"error": "Failed to decode JSON from Gemini response."}
36
 
37
- # Recursively break down each step if possible
38
- for step in steps:
39
- step_reactants = steps[step][0] # reactants in this step
40
- step_products = steps[step][1] # products in this step
41
- reason = steps[step][2] # reason in this step
42
-
43
- if reason != "found through experiment":
44
- substeps = generate_substeps(step_reactants, step_products)
45
- steps[step].append({"substeps": substeps})
46
-
47
  return steps
48
 
49
  # Gradio interface
50
  def process_reaction(reactants, products):
51
- steps = generate_substeps(reactants, products)
52
  return json.dumps(steps, indent=4)
53
 
54
  # Create the Gradio interface
@@ -57,7 +47,7 @@ iface = gr.Interface(
57
  inputs=[gr.Textbox(label="Reactants (comma-separated)"), gr.Textbox(label="Products (comma-separated)")],
58
  outputs="json",
59
  title="Chemistry Rationalizer",
60
- description="Break down a reaction mechanism into recursive steps."
61
  )
62
 
63
  if __name__ == "__main__":
 
21
  generation_config=generation_config,
22
  )
23
 
24
+ # Function to generate steps for A -> D flow
25
+ def generate_reaction_steps(reactants, products):
26
  prompt = f"Given reactants: {reactants} and products: {products}, break down the reaction mechanism into simple steps and provide in JSON format."
27
 
28
  chat_session = model.start_chat(history=[])
 
34
  except json.JSONDecodeError:
35
  steps = {"error": "Failed to decode JSON from Gemini response."}
36
 
 
 
 
 
 
 
 
 
 
 
37
  return steps
38
 
39
  # Gradio interface
40
  def process_reaction(reactants, products):
41
+ steps = generate_reaction_steps(reactants, products)
42
  return json.dumps(steps, indent=4)
43
 
44
  # Create the Gradio interface
 
47
  inputs=[gr.Textbox(label="Reactants (comma-separated)"), gr.Textbox(label="Products (comma-separated)")],
48
  outputs="json",
49
  title="Chemistry Rationalizer",
50
+ description="Break down a reaction mechanism into simple steps."
51
  )
52
 
53
  if __name__ == "__main__":