Amelia-James commited on
Commit
b98d07a
·
verified ·
1 Parent(s): 25ac852

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -21
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 as a 35-year experienced educator
13
  def generate_mcqs_from_text(user_text):
14
  prompt = f"""
15
- You are a 35-year experienced educator specializing in crafting challenging and insightful MCQs.
16
- Based on the following text, generate between 30 to 50 multiple-choice questions (MCQs).
17
- Each question should:
18
- 1. Test critical thinking and understanding of the content.
19
- 2. Include four options (A, B, C, D), with one correct answer and three well-designed distractors.
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 Groq-supported model
35
  )
36
  return chat_completion.choices[0].message.content
37
 
38
- # Function to evaluate MCQ answers like an experienced teacher
39
  def evaluate_answers(mcqs, user_answers):
40
  prompt = f"""
41
- You are a 35-year experienced educator evaluating student answers.
42
- The student has completed the following MCQs. Please:
43
- 1. Check the correctness of each answer.
44
- 2. Provide detailed feedback for each question, explaining why the student's choice is correct or incorrect.
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 Groq-supported model
53
  )
54
  return chat_completion.choices[0].message.content
55
 
56
  # Streamlit App
57
- st.title("Experienced Educator MCQ Generator & Evaluator")
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..."):