shukdevdatta123 commited on
Commit
538869a
·
verified ·
1 Parent(s): 5616aae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -58,6 +58,15 @@ def fix_code_bugs(buggy_code, model="gpt-4o-mini"):
58
  )
59
  return response['choices'][0]['message']['content']
60
 
 
 
 
 
 
 
 
 
 
61
  from PIL import Image # Required for local image files
62
 
63
  # Streamlit app starts here
@@ -289,15 +298,17 @@ if openai_api_key:
289
  # User input for math questions
290
  math_query = st.text_input("Ask a mathematics-related question:")
291
 
292
- if math_query:
293
- with st.spinner("Getting answer..."):
294
- prompt = f"Answer the following math question: {math_query}"
295
- response = openai.ChatCompletion.create(
296
- model="gpt-4o-mini",
297
- messages=[{"role": "user", "content": prompt}]
298
- )
299
- answer = response['choices'][0]['message']['content']
300
- st.write(f"### Answer: {answer}")
 
 
301
 
302
  # **New Section: Biology Assistant**
303
  elif mode == "Biology Assistant":
 
58
  )
59
  return response['choices'][0]['message']['content']
60
 
61
+ # Function to generate AI-based mathematical solutions
62
+ def generate_math_solution(query):
63
+ prompt = f"Explain and solve the following mathematical problem step by step: {query}"
64
+ response = openai.ChatCompletion.create(
65
+ model="gpt-4o-mini",
66
+ messages=[{"role": "user", "content": prompt}]
67
+ )
68
+ return response['choices'][0]['message']['content']
69
+
70
  from PIL import Image # Required for local image files
71
 
72
  # Streamlit app starts here
 
298
  # User input for math questions
299
  math_query = st.text_input("Ask a mathematics-related question:")
300
 
301
+ if st.button("Solve Problem"):
302
+ if math_query:
303
+ with st.spinner("Generating solution..."):
304
+ # Generate the solution using GPT-4
305
+ solution = generate_math_solution(math_query)
306
+
307
+ # Render the solution with LaTeX for mathematical notations
308
+ st.write("### Solution and Explanation:")
309
+ st.markdown(f"**Solution:**\n\n{solution}")
310
+ else:
311
+ st.error("Please enter a math problem to solve.")
312
 
313
  # **New Section: Biology Assistant**
314
  elif mode == "Biology Assistant":