import streamlit as st from langchain_google_genai import ChatGoogleGenerativeAI # Set the title of the app st.title("MathMind Arena") # Initialize the language model with the provided API key llm = ChatGoogleGenerativeAI( model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"] ) def generate_math_quiz(role, topic, difficulty, num_questions): """ Generates a math quiz based on the role, topic, difficulty, and number of questions. Args: role (str): The role of the user (e.g., student, teacher). topic (str): The topic for the quiz (e.g., Algebra, Calculus). difficulty (str): The difficulty level (e.g., Easy, Medium, Hard). num_questions (int): The number of questions to generate. Returns: str: The generated quiz questions. """ # Construct the prompt for the model prompt = ( f"Create a {num_questions}-question math quiz for a {role} on the topic of {topic}. " f"The questions should be of {difficulty} difficulty level. " "Provide answers and make sure the questions are clear and varied." ) # Generate the response from the language model response = llm.invoke(prompt) # Extract the content from the response return response.content # Create a form for user input with st.form("quiz_form"): # Dropdown for selecting the role role = st.selectbox("Select Role", ["Student", "Teacher", "Researcher"]) # Dropdown for selecting the topic topic = st.selectbox("Select Topic", ["Algebra", "Calculus", "Geometry", "Statistics"]) # Dropdown for selecting the difficulty level difficulty = st.selectbox("Select Difficulty", ["Easy", "Medium", "Hard"]) # Input for the number of questions num_questions = st.number_input("Number of Questions", min_value=1, max_value=20, value=5) # Submit button for the form submitted = st.form_submit_button("Generate Quiz") # Handle form submission if submitted: if role and topic and difficulty: # Generate quiz questions based on the user input quiz = generate_math_quiz(role, topic, difficulty, num_questions) st.info(quiz) # Display the generated quiz questions else: st.error("Please fill in all fields to generate the quiz.")