Spaces:
Sleeping
Sleeping
Amelia-James
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -9,17 +9,14 @@ load_dotenv()
|
|
9 |
# Initialize the Groq client with API key
|
10 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
11 |
|
12 |
-
# Function to generate MCQs
|
13 |
def generate_mcqs_from_text(user_text):
|
14 |
prompt = f"""
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
3. Provide clear, concise language and avoid ambiguity.
|
21 |
-
|
22 |
-
Format the output as:
|
23 |
Question: [Your question here]
|
24 |
A. [Option 1]
|
25 |
B. [Option 2]
|
@@ -31,30 +28,28 @@ def generate_mcqs_from_text(user_text):
|
|
31 |
"""
|
32 |
chat_completion = client.chat.completions.create(
|
33 |
messages=[{"role": "user", "content": prompt}],
|
34 |
-
model="gemma2-9b-it", # Use a valid
|
35 |
)
|
36 |
return chat_completion.choices[0].message.content
|
37 |
|
38 |
-
# Function to evaluate
|
39 |
def evaluate_answers(mcqs, user_answers):
|
40 |
prompt = f"""
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
3. Assign an overall score and include advice for improvement.
|
46 |
-
|
47 |
MCQs: {mcqs}
|
48 |
User Answers: {user_answers}
|
49 |
"""
|
50 |
chat_completion = client.chat.completions.create(
|
51 |
messages=[{"role": "user", "content": prompt}],
|
52 |
-
model="gemma2-9b-it", # Use a valid
|
53 |
)
|
54 |
return chat_completion.choices[0].message.content
|
55 |
|
56 |
# Streamlit App
|
57 |
-
st.title("
|
58 |
st.sidebar.header("Input Settings")
|
59 |
|
60 |
# Input text from user
|
@@ -72,9 +67,7 @@ if st.sidebar.button("Generate MCQs"):
|
|
72 |
|
73 |
# Input user answers for evaluation
|
74 |
if "mcqs" in st.session_state:
|
75 |
-
st.subheader("Solve the MCQs")
|
76 |
user_answers = st.text_area("Enter your answers (e.g., A, B, C, D for each question):", height=100)
|
77 |
-
|
78 |
if st.button("Evaluate Answers"):
|
79 |
if user_answers.strip():
|
80 |
with st.spinner("Evaluating answers..."):
|
|
|
9 |
# Initialize the Groq client with API key
|
10 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
11 |
|
12 |
+
# Function to generate MCQs based on the input text
|
13 |
def generate_mcqs_from_text(user_text):
|
14 |
prompt = f"""
|
15 |
+
Based on the following text, generate between 30 to 50 multiple-choice questions.
|
16 |
+
Each question should have four answer options, with one correct answer and three distractors.
|
17 |
+
Make sure the questions are clear and test the user's understanding of the content.
|
18 |
+
Provide the questions in the following format:
|
19 |
+
|
|
|
|
|
|
|
20 |
Question: [Your question here]
|
21 |
A. [Option 1]
|
22 |
B. [Option 2]
|
|
|
28 |
"""
|
29 |
chat_completion = client.chat.completions.create(
|
30 |
messages=[{"role": "user", "content": prompt}],
|
31 |
+
model="gemma2-9b-it", # Use a valid model that supports chat completions
|
32 |
)
|
33 |
return chat_completion.choices[0].message.content
|
34 |
|
35 |
+
# Function to evaluate user answers
|
36 |
def evaluate_answers(mcqs, user_answers):
|
37 |
prompt = f"""
|
38 |
+
Here are the user's answers to the following multiple-choice questions.
|
39 |
+
Please evaluate them as an experienced teacher, providing feedback on correctness,
|
40 |
+
and explain why each answer is right or wrong.
|
41 |
+
|
|
|
|
|
42 |
MCQs: {mcqs}
|
43 |
User Answers: {user_answers}
|
44 |
"""
|
45 |
chat_completion = client.chat.completions.create(
|
46 |
messages=[{"role": "user", "content": prompt}],
|
47 |
+
model="gemma2-9b-it", # Use a valid model
|
48 |
)
|
49 |
return chat_completion.choices[0].message.content
|
50 |
|
51 |
# Streamlit App
|
52 |
+
st.title("Study Assistant - MCQ Generator & Evaluator")
|
53 |
st.sidebar.header("Input Settings")
|
54 |
|
55 |
# Input text from user
|
|
|
67 |
|
68 |
# Input user answers for evaluation
|
69 |
if "mcqs" in st.session_state:
|
|
|
70 |
user_answers = st.text_area("Enter your answers (e.g., A, B, C, D for each question):", height=100)
|
|
|
71 |
if st.button("Evaluate Answers"):
|
72 |
if user_answers.strip():
|
73 |
with st.spinner("Evaluating answers..."):
|