File size: 1,141 Bytes
b3d7e23
dc4b7c7
b3d7e23
dc4b7c7
 
b3d7e23
dc4b7c7
b3d7e23
dc4b7c7
276b1f5
dc4b7c7
 
 
 
 
 
 
b3d7e23
 
 
dc4b7c7
b3d7e23
 
 
 
 
 
 
 
dc4b7c7
b3d7e23
 
 
9834515
 
6a0291c
648d0d6
dc4b7c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.")