Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
46 |
-
# Extract the JSON
|
47 |
try:
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
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)
|