Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
# Function to generate MCQs
|
8 |
def generate_mcqs(content, num_questions):
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
return questions
|
12 |
|
13 |
# Streamlit UI
|
14 |
-
st.title("MCQ Generator using
|
15 |
|
16 |
content = st.text_area("Enter the content from which MCQs will be generated:", height=200)
|
17 |
num_questions = st.number_input("Enter the number of MCQs to generate:", min_value=1, max_value=20, value=5, step=1)
|
@@ -20,7 +27,7 @@ if st.button("Generate MCQs"):
|
|
20 |
if content:
|
21 |
mcqs = generate_mcqs(content, num_questions)
|
22 |
for i, mcq in enumerate(mcqs):
|
23 |
-
st.write(f"Q{i+1}: {mcq
|
24 |
else:
|
25 |
st.warning("Please enter the content to generate MCQs.")
|
26 |
|
@@ -28,3 +35,4 @@ if st.button("Generate MCQs"):
|
|
28 |
|
29 |
|
30 |
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import openai
|
3 |
|
4 |
+
# Set the API key
|
5 |
+
openai.api_key = "sk-proj-uHasdgbriPPlFMm99ZtJT3BlbkFJOl231YfdxCSNmQjVEpMX"
|
6 |
|
7 |
+
# Function to generate MCQs using OpenAI
|
8 |
def generate_mcqs(content, num_questions):
|
9 |
+
response = openai.Completion.create(
|
10 |
+
engine="davinci-codex", # You can use a different engine if needed
|
11 |
+
prompt=f"Generate {num_questions} multiple-choice questions from the following content:\n\n{content}\n\n",
|
12 |
+
max_tokens=500,
|
13 |
+
n=num_questions,
|
14 |
+
stop=None,
|
15 |
+
temperature=0.7
|
16 |
+
)
|
17 |
+
questions = [choice["text"].strip() for choice in response.choices]
|
18 |
return questions
|
19 |
|
20 |
# Streamlit UI
|
21 |
+
st.title("MCQ Generator using OpenAI")
|
22 |
|
23 |
content = st.text_area("Enter the content from which MCQs will be generated:", height=200)
|
24 |
num_questions = st.number_input("Enter the number of MCQs to generate:", min_value=1, max_value=20, value=5, step=1)
|
|
|
27 |
if content:
|
28 |
mcqs = generate_mcqs(content, num_questions)
|
29 |
for i, mcq in enumerate(mcqs):
|
30 |
+
st.write(f"Q{i+1}: {mcq}")
|
31 |
else:
|
32 |
st.warning("Please enter the content to generate MCQs.")
|
33 |
|
|
|
35 |
|
36 |
|
37 |
|
38 |
+
|