|
import streamlit as st |
|
|
|
|
|
from langchain_community.llms import OpenAI |
|
from langchain_google_genai import ChatGoogleGenerativeAI |
|
|
|
def get_answers(questions,model): |
|
st.write("running get answers function answering following questions",questions) |
|
|
|
|
|
answer_prompt = (f"Answer the following questions {questions}") |
|
|
|
|
|
if model == "Open AI": |
|
llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"]) |
|
answers = llm(answer_prompt) |
|
|
|
|
|
elif model == "Gemini": |
|
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"]) |
|
answers = llm.invoke(answer_prompt) |
|
answers = answers.content |
|
|
|
|
|
return(answers) |
|
|
|
|
|
|
|
|
|
def GetLLMResponse(selected_topic_level, selected_topic,num_quizzes, model): |
|
|
|
|
|
|
|
st.write("Selected option:", selected_topic_level,selected_topic,num_quizzes) |
|
|
|
|
|
|
|
question_prompt = (f'I want you to just generate question with this specification: Generate a {selected_topic_level} math quiz on the topic of {selected_topic}. Generate only {num_quizzes} questions not more and without providing answers.') |
|
|
|
st.write("running get llm response and print question prompt",question_prompt) |
|
if model == "Open AI": |
|
llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"]) |
|
questions = llm(question_prompt) |
|
|
|
|
|
elif model == "Gemini": |
|
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"]) |
|
questions = llm.invoke(question_prompt) |
|
questions = questions.content |
|
|
|
|
|
|
|
st.write("print questions",questions) |
|
answers = get_answers(questions,model) |
|
|
|
|
|
return(questions,answers) |
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config(page_title="Generate Math Quizzes", |
|
page_icon="🧮", |
|
layout="wide", |
|
initial_sidebar_state="collapsed") |
|
|
|
|
|
|
|
|
|
def main(): |
|
math_topics = { |
|
"Elementary School Level": ["Basic Arithmetic", "Place Value", "Fraction", "Decimals", "Geomerty"], |
|
"Middle School Level": ["Algebra", "Ratio and Proportion", "Percentages", "Geometry", "Integers and Rational Numbers"], |
|
"High School Level": ["Algebra II", "Trigonometry", "Pre-Calculus", "Calculus", "Statistics and Probability"] |
|
} |
|
|
|
st.header("Select AI:") |
|
model = st.radio("Model", [ "Gemini","Open AI",]) |
|
st.write("Selected option:", model) |
|
|
|
|
|
|
|
|
|
st.title("Generate Math Quizzes 🧮") |
|
st.text("Choose the difficulty level and topic for your math quizzes.") |
|
|
|
|
|
|
|
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 Quizzes', min_value=1, max_value= 5, value=1) |
|
|
|
submit = st.button('Generate Quizzes') |
|
st.write("Selected option:", selected_topic_level,selected_topic,num_quizzes) |
|
|
|
|
|
if submit: |
|
questions,answers = GetLLMResponse(selected_topic_level, selected_topic, num_quizzes, model) |
|
st.write("printing the response",questions,answers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
st.warning("Click the 'Generate Quizzes' button to create quizzes.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
main() |