Spaces:
Runtime error
Runtime error
File size: 1,729 Bytes
39c84a2 a8b70d3 39c84a2 a8b70d3 39c84a2 3bf7b96 a0862f6 3bf7b96 39c84a2 a8b70d3 a0862f6 a8b70d3 a0862f6 a8b70d3 a0862f6 39c84a2 a0862f6 a8b70d3 a0862f6 39c84a2 a8b70d3 a0862f6 a8b70d3 39c84a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import genai # Assuming this is the correct library for Gemini API
import sympy as sp
# Set up the Gemini model
model = genai.GenerativeModel("gemini-1.5-flash")
# Function for algebraic simplification
def algebra_simplification(expression):
try:
expr = sp.sympify(expression)
simplified_expr = sp.simplify(expr)
return str(simplified_expr)
except Exception as e:
return f"Error: {str(e)}"
# Function for solving algebraic equations
def algebra_solve(equation):
try:
eq = sp.sympify(equation)
variables = list(eq.free_symbols)
solutions = sp.solve(eq, *variables)
return str(solutions)
except Exception as e:
return f"Error: {str(e)}"
# Function to handle the chat with Gemini
def process_math_problem(math_problem):
chat = model.start_chat(
history=[
{"role": "user", "parts": "Hello"},
{"role": "model", "parts": "Great to meet you. What would you like to know?"},
]
)
# Send the math problem to Gemini
response = chat.send_message(math_problem)
# Return Gemini's response
return response.text
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Gemini Algebra Solver")
# Single input field for math problems
input_problem = gr.Textbox(label="Enter a Math Problem", placeholder="e.g., Simplify (x^2 - 4)/(x - 2) or Solve x^2 - 4 = 0")
output_solution = gr.Textbox(label="Solution")
# Button to trigger the solution process
solve_button = gr.Button("Solve")
solve_button.click(fn=process_math_problem, inputs=input_problem, outputs=output_solution)
# Launch the Gradio interface
demo.launch()
|