Spaces:
Sleeping
Sleeping
Amelia-James
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,83 +1,3 @@
|
|
1 |
-
# import os
|
2 |
-
# from dotenv import load_dotenv
|
3 |
-
# from groq import Groq
|
4 |
-
# import streamlit as st
|
5 |
-
|
6 |
-
# # Load environment variables
|
7 |
-
# load_dotenv()
|
8 |
-
|
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]
|
23 |
-
# C. [Option 3]
|
24 |
-
# D. [Option 4]
|
25 |
-
# Correct Answer: [Correct Option]
|
26 |
-
|
27 |
-
# Text: {user_text}
|
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
|
56 |
-
# user_text = st.sidebar.text_area("Enter the text for generating MCQs:", height=200)
|
57 |
-
|
58 |
-
# if st.sidebar.button("Generate MCQs"):
|
59 |
-
# if user_text.strip():
|
60 |
-
# with st.spinner("Generating MCQs..."):
|
61 |
-
# mcqs = generate_mcqs_from_text(user_text)
|
62 |
-
# st.subheader("Generated MCQs:")
|
63 |
-
# st.text_area("MCQs", value=mcqs, height=400)
|
64 |
-
# st.session_state["mcqs"] = mcqs # Store MCQs for evaluation
|
65 |
-
# else:
|
66 |
-
# st.error("Please enter text for generating MCQs.")
|
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..."):
|
74 |
-
# evaluation_result = evaluate_answers(st.session_state["mcqs"], user_answers)
|
75 |
-
# st.subheader("Evaluation Result:")
|
76 |
-
# st.text_area("Evaluation", value=evaluation_result, height=400)
|
77 |
-
# else:
|
78 |
-
# st.error("Please enter your answers for evaluation.")
|
79 |
-
|
80 |
-
|
81 |
import os
|
82 |
from dotenv import load_dotenv
|
83 |
from groq import Groq
|
@@ -98,7 +18,7 @@ def generate_mcqs_from_text(user_text):
|
|
98 |
1. Test critical thinking and understanding of the content.
|
99 |
2. Include four options (A, B, C, D), with one correct answer and three well-designed distractors.
|
100 |
3. Provide clear, concise language and avoid ambiguity.
|
101 |
-
4.
|
102 |
|
103 |
Format the output as:
|
104 |
Question: [Your question here]
|
@@ -116,6 +36,12 @@ def generate_mcqs_from_text(user_text):
|
|
116 |
)
|
117 |
return chat_completion.choices[0].message.content
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
# Streamlit App
|
120 |
st.title("MCQ Generator with Correct Answers")
|
121 |
st.write("Paste your text below, and the app will generate MCQs with the correct answers.")
|
@@ -127,15 +53,8 @@ if st.button("Generate MCQs"):
|
|
127 |
if user_text.strip():
|
128 |
with st.spinner("Generating MCQs..."):
|
129 |
mcqs = generate_mcqs_from_text(user_text)
|
|
|
130 |
st.subheader("Generated MCQs with Correct Answers:")
|
131 |
-
st.text_area("MCQs", value=
|
132 |
else:
|
133 |
st.error("Please enter text for generating MCQs.")
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
from groq import Groq
|
|
|
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 |
+
4. Avoid using any special characters or formatting like '*' or '#' in the output.
|
22 |
|
23 |
Format the output as:
|
24 |
Question: [Your question here]
|
|
|
36 |
)
|
37 |
return chat_completion.choices[0].message.content
|
38 |
|
39 |
+
# Function to clean the output and remove unwanted characters
|
40 |
+
def clean_output(mcqs):
|
41 |
+
# Remove special characters like '*' and '#'
|
42 |
+
mcqs = mcqs.replace("*", "").replace("#", "")
|
43 |
+
return mcqs
|
44 |
+
|
45 |
# Streamlit App
|
46 |
st.title("MCQ Generator with Correct Answers")
|
47 |
st.write("Paste your text below, and the app will generate MCQs with the correct answers.")
|
|
|
53 |
if user_text.strip():
|
54 |
with st.spinner("Generating MCQs..."):
|
55 |
mcqs = generate_mcqs_from_text(user_text)
|
56 |
+
cleaned_mcqs = clean_output(mcqs) # Clean the MCQs output
|
57 |
st.subheader("Generated MCQs with Correct Answers:")
|
58 |
+
st.text_area("MCQs", value=cleaned_mcqs, height=600)
|
59 |
else:
|
60 |
st.error("Please enter text for generating MCQs.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|