import streamlit as st from langchain_google_genai import ChatGoogleGenerativeAI import os key = os.getenv('api_key') llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=key) math_topics = { "Middle school": ["Arithmetics", "Place Value", "Number line", "Geomerty"], "High school": ["Algebra", "Ratios", "Percentage", "Construction of Geometry"], "University": ["Complex Algebra", "Trigonometric Functions", "Calculus", "Three-Dimensional Geometry", "Statistics and Probability"] } st.title("Generate a Math Quiz") st.write("Kindly select what level of questions, the topic and the number of questions required in the quiz") col1, col2, col3 = st.columns([1, 1, 1]) with col1: selected_topic_level = st.selectbox('Select Topic Level', list(math_topics.keys())) with col2: selected_topic = st.selectbox('Select Topic', math_topics[selected_topic_level]) with col3: num_quizzes = st.slider('Number of Questions', min_value=1, max_value= 5, value=1) submit = st.button('Generate Quizzes') if submit: with st.spinner("Generating Quizzes..."): prompt = f"Generate {num_quizzes} number of problems on the topic {selected_topic} with a difficult level of {selected_topic_level}. Output the questions only. Also provide the answer below each question." res = llm.invoke(prompt) response = res.content st.success("Quizzes Generated!") if response: st.subheader("Quiz Questions and Answers:") st.write(response) else: st.warning("No Quiz Questions and Answers") else: st.warning("Click the 'Generate Quizzes' button to create quizzes.")