from langchain_groq import ChatGroq from langchain_core.prompts import PromptTemplate import streamlit as st import os groq_api_key = st.secrets["API_KEY"] os.environ["GROQ_API_KEY"] = groq_api_key chat = ChatGroq(temperature=0, model_name="mixtral-8x7b-32768") template = """ You are an expert in creating engaging and funny quiz questions for various audiences. Your task is to generate math quiz questions around the given topic for the host to use. Make sure the questions are engaging, funny, and tailored to the audience's expertise level and role. **ROLE**: {role} **TOPIC**: {topic} **AUDIENCE EXPERTISE**: {audience_expertise} **NUMBER OF QUESTIONS**: {num_questions} -Generate the quiz questions and provide them with the correct answers. -Generate mcq types questions with 4 options each. """ prompt = PromptTemplate(template=template) st.title("Math Quiz Bot") # Collect user input for the quiz parameters role = st.selectbox("Select the audience role:", ["Student", "Teacher", "Engineer", "Data Scientist", "Data Analyst"]) topic = st.selectbox("Select the topic:", ["Algebra", "Calculus", "Geometry", "Statistics"]) audience_expertise = st.selectbox("Select the audience expertise level:", ["Beginner", "Intermediate", "Expert"]) num_questions = st.number_input("Enter the number of questions:", min_value=1, max_value=50) if st.button("Generate Quiz"): # Format the prompt with the collected details input_prompt = prompt.format( topic=topic, role=role, audience_expertise=audience_expertise, num_questions=num_questions ) st.write("**Generated Prompt:**") st.write(input_prompt) # Invoke the chat model and get the response response = chat.invoke(input_prompt) st.write("**Generated Quiz Questions:**") st.write(response.content)