|
import streamlit as st |
|
from langchain_google_genai import ChatGoogleGenerativeAI |
|
|
|
|
|
st.title("MathMind Arena") |
|
|
|
|
|
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. |
|
""" |
|
|
|
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." |
|
) |
|
|
|
|
|
response = llm.invoke(prompt) |
|
|
|
|
|
return response.content |
|
|
|
|
|
with st.form("quiz_form"): |
|
|
|
role = st.selectbox("Select Role", ["Student", "Teacher", "Researcher"]) |
|
|
|
|
|
topic = st.selectbox("Select Topic", ["Algebra", "Calculus", "Geometry", "Statistics"]) |
|
|
|
|
|
difficulty = st.selectbox("Select Difficulty", ["Easy", "Medium", "Hard"]) |
|
|
|
|
|
num_questions = st.number_input("Number of Questions", min_value=1, max_value=20, value=5) |
|
|
|
|
|
submitted = st.form_submit_button("Generate Quiz") |
|
|
|
|
|
if submitted: |
|
if role and topic and difficulty: |
|
|
|
quiz = generate_math_quiz(role, topic, difficulty, num_questions) |
|
st.info(quiz) |
|
else: |
|
st.error("Please fill in all fields to generate the quiz.") |
|
|