File size: 2,347 Bytes
8cda756
 
 
 
1c3d281
8cda756
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60aefb4
8cda756
 
 
 
 
 
 
 
 
 
 
 
60aefb4
8cda756
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60aefb4
 
8cda756
 
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
57
58
59
60
61
62
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.")