import streamlit as st import openai # Set the API key openai.api_key = "sk-proj-uHasdgbriPPlFMm99ZtJT3BlbkFJOl231YfdxCSNmQjVEpMX" # Function to generate MCQs using OpenAI def generate_mcqs(content, num_questions): response = openai.Completion.create( # You can use a different engine if needed prompt=f"Generate {num_questions} multiple-choice questions from the following content:\n\n{content}\n\n", max_tokens=500, n=num_questions, stop=None, temperature=0.7 ) questions = [choice["text"].strip() for choice in response.choices] return questions # Streamlit UI st.title("MCQ Generator using OpenAI") content = st.text_area("Enter the content from which MCQs will be generated:", height=200) num_questions = st.number_input("Enter the number of MCQs to generate:", min_value=1, max_value=20, value=5, step=1) if st.button("Generate MCQs"): if content: mcqs = generate_mcqs(content, num_questions) for i, mcq in enumerate(mcqs): st.write(f"Q{i+1}: {mcq}") else: st.warning("Please enter the content to generate MCQs.")