Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,24 +6,39 @@ import gradio as gr
|
|
6 |
# Configure the Gemini API
|
7 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
|
|
17 |
|
18 |
-
# Define the model
|
19 |
model = genai.GenerativeModel(
|
20 |
model_name="gemini-1.5-flash",
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
27 |
|
28 |
chat_session = model.start_chat(history=[])
|
29 |
response = chat_session.send_message(prompt)
|
|
|
6 |
# Configure the Gemini API
|
7 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
8 |
|
9 |
+
# Define the system instruction (pre_prompt)
|
10 |
+
pre_prompt = """
|
11 |
+
You are a chemistry expert. Break down the given chemical reaction mechanism into simple steps.
|
12 |
+
The output should be in JSON format with the following structure:
|
13 |
+
|
14 |
+
{
|
15 |
+
"step 1": {
|
16 |
+
"reactants": ["reactant 1", "reactant 2"],
|
17 |
+
"products": ["product 1", "product 2"],
|
18 |
+
"reason": "Describe the reason or logic behind this step",
|
19 |
+
"reagent": "Optional reagent or conditions for this step"
|
20 |
+
},
|
21 |
+
"step 2": { ... }
|
22 |
+
...
|
23 |
}
|
24 |
+
"""
|
25 |
|
26 |
+
# Define the model with the system instruction (pre_prompt)
|
27 |
model = genai.GenerativeModel(
|
28 |
model_name="gemini-1.5-flash",
|
29 |
+
system_instruction=pre_prompt,
|
30 |
+
generation_config={
|
31 |
+
"temperature": 1,
|
32 |
+
"top_p": 0.95,
|
33 |
+
"top_k": 64,
|
34 |
+
"max_output_tokens": 8192,
|
35 |
+
"response_mime_type": "text/plain",
|
36 |
+
},
|
37 |
)
|
38 |
|
39 |
# Function to generate steps for A -> D flow
|
40 |
def generate_reaction_steps(reactants, products):
|
41 |
+
prompt = f"Given reactants: {reactants} and products: {products}, break down the reaction mechanism into simple steps in JSON format."
|
42 |
|
43 |
chat_session = model.start_chat(history=[])
|
44 |
response = chat_session.send_message(prompt)
|