Update app.py
Browse files
app.py
CHANGED
|
@@ -23,12 +23,13 @@ class QuizFeedback:
|
|
| 23 |
selected: Optional[str]
|
| 24 |
correct_answer: str
|
| 25 |
|
|
|
|
| 26 |
class QuizGenerator:
|
| 27 |
def __init__(self, api_key: str):
|
| 28 |
self.client = Groq(api_key=api_key)
|
| 29 |
|
| 30 |
-
def generate_questions(self, text: str, num_questions: int) -> List[Question]:
|
| 31 |
-
"""Generate quiz questions using gemma2-9b-it"""
|
| 32 |
prompt = self._create_prompt(text, num_questions)
|
| 33 |
|
| 34 |
try:
|
|
@@ -44,7 +45,7 @@ class QuizGenerator:
|
|
| 44 |
}
|
| 45 |
],
|
| 46 |
model="gemma2-9b-it",
|
| 47 |
-
temperature=
|
| 48 |
max_tokens=6000
|
| 49 |
)
|
| 50 |
|
|
@@ -665,13 +666,13 @@ Continue your learning journey by experimenting with different features, challen
|
|
| 665 |
"""Get certificate title with difficulty level"""
|
| 666 |
return f"{base_title} - {self.selected_level} Level"
|
| 667 |
|
| 668 |
-
def generate_questions(self, text: str, num_questions: int) -> Tuple[bool, List[Question]]:
|
| 669 |
"""
|
| 670 |
Generate quiz questions using the QuizGenerator
|
| 671 |
Returns (success, questions) tuple
|
| 672 |
"""
|
| 673 |
try:
|
| 674 |
-
questions = self.quiz_generator.generate_questions(text, num_questions)
|
| 675 |
self.current_questions = questions
|
| 676 |
return True, questions
|
| 677 |
except Exception as e:
|
|
@@ -881,6 +882,15 @@ def create_quiz_interface():
|
|
| 881 |
label="Select Difficulty Level",
|
| 882 |
info="Basic: 5 questions | Intermediate: 10 questions | Advanced: 20 questions")
|
| 883 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
|
| 885 |
with gr.Row():
|
| 886 |
participant_photo = gr.Image(label="Your Photo (Optional)", type="filepath")
|
|
@@ -960,11 +970,10 @@ def create_quiz_interface():
|
|
| 960 |
|
| 961 |
|
| 962 |
# Helper Functions
|
| 963 |
-
def on_generate_questions(text, level):
|
| 964 |
-
quiz_app.selected_level = level
|
| 965 |
-
num_questions = quiz_app.difficulty_levels[level]
|
| 966 |
-
|
| 967 |
-
success, questions = quiz_app.generate_questions(quiz_app.fixed_content, num_questions)
|
| 968 |
if not success or not questions:
|
| 969 |
return [
|
| 970 |
"",
|
|
@@ -1124,7 +1133,7 @@ def create_quiz_interface():
|
|
| 1124 |
# Event Handlers
|
| 1125 |
generate_btn.click(
|
| 1126 |
fn=on_generate_questions,
|
| 1127 |
-
inputs=[text_input, difficulty_level
|
| 1128 |
outputs=[
|
| 1129 |
question_display,
|
| 1130 |
question_box,
|
|
@@ -1137,7 +1146,6 @@ def create_quiz_interface():
|
|
| 1137 |
results_group,
|
| 1138 |
view_cert_btn
|
| 1139 |
]
|
| 1140 |
-
)
|
| 1141 |
|
| 1142 |
prev_btn.click(
|
| 1143 |
fn=handle_prev,
|
|
@@ -1168,7 +1176,7 @@ def create_quiz_interface():
|
|
| 1168 |
|
| 1169 |
reset_btn.click(
|
| 1170 |
fn=on_generate_questions,
|
| 1171 |
-
inputs=[text_input, difficulty_level
|
| 1172 |
outputs=[
|
| 1173 |
question_display,
|
| 1174 |
question_box,
|
|
@@ -1182,7 +1190,7 @@ def create_quiz_interface():
|
|
| 1182 |
view_cert_btn
|
| 1183 |
]
|
| 1184 |
)
|
| 1185 |
-
|
| 1186 |
view_cert_btn.click(
|
| 1187 |
fn=show_certificate_tab,
|
| 1188 |
outputs=[cert_tab, course_name, tabs] # Add course_name to outputs
|
|
|
|
| 23 |
selected: Optional[str]
|
| 24 |
correct_answer: str
|
| 25 |
|
| 26 |
+
|
| 27 |
class QuizGenerator:
|
| 28 |
def __init__(self, api_key: str):
|
| 29 |
self.client = Groq(api_key=api_key)
|
| 30 |
|
| 31 |
+
def generate_questions(self, text: str, num_questions: int, temperature: float = 0) -> List[Question]:
|
| 32 |
+
"""Generate quiz questions using gemma2-9b-it with temperature control"""
|
| 33 |
prompt = self._create_prompt(text, num_questions)
|
| 34 |
|
| 35 |
try:
|
|
|
|
| 45 |
}
|
| 46 |
],
|
| 47 |
model="gemma2-9b-it",
|
| 48 |
+
temperature=temperature, # Use the temperature parameter
|
| 49 |
max_tokens=6000
|
| 50 |
)
|
| 51 |
|
|
|
|
| 666 |
"""Get certificate title with difficulty level"""
|
| 667 |
return f"{base_title} - {self.selected_level} Level"
|
| 668 |
|
| 669 |
+
def generate_questions(self, text: str, num_questions: int, temperature: float) -> Tuple[bool, List[Question]]:
|
| 670 |
"""
|
| 671 |
Generate quiz questions using the QuizGenerator
|
| 672 |
Returns (success, questions) tuple
|
| 673 |
"""
|
| 674 |
try:
|
| 675 |
+
questions = self.quiz_generator.generate_questions(text, num_questions, temperature)
|
| 676 |
self.current_questions = questions
|
| 677 |
return True, questions
|
| 678 |
except Exception as e:
|
|
|
|
| 882 |
label="Select Difficulty Level",
|
| 883 |
info="Basic: 5 questions | Intermediate: 10 questions | Advanced: 20 questions")
|
| 884 |
|
| 885 |
+
# Add temperature slider
|
| 886 |
+
temperature = gr.Slider(
|
| 887 |
+
minimum=0,
|
| 888 |
+
maximum=1,
|
| 889 |
+
value=0,
|
| 890 |
+
step=0.1,
|
| 891 |
+
label="Question Creativity Level",
|
| 892 |
+
info="0 = More focused, 1 = More creative"
|
| 893 |
+
)
|
| 894 |
|
| 895 |
with gr.Row():
|
| 896 |
participant_photo = gr.Image(label="Your Photo (Optional)", type="filepath")
|
|
|
|
| 970 |
|
| 971 |
|
| 972 |
# Helper Functions
|
| 973 |
+
def on_generate_questions(text, level, temp):
|
| 974 |
+
quiz_app.selected_level = level
|
| 975 |
+
num_questions = quiz_app.difficulty_levels[level]
|
| 976 |
+
success, questions = quiz_app.generate_questions(quiz_app.fixed_content, num_questions, temp)
|
|
|
|
| 977 |
if not success or not questions:
|
| 978 |
return [
|
| 979 |
"",
|
|
|
|
| 1133 |
# Event Handlers
|
| 1134 |
generate_btn.click(
|
| 1135 |
fn=on_generate_questions,
|
| 1136 |
+
inputs=[text_input, difficulty_level, temperature],
|
| 1137 |
outputs=[
|
| 1138 |
question_display,
|
| 1139 |
question_box,
|
|
|
|
| 1146 |
results_group,
|
| 1147 |
view_cert_btn
|
| 1148 |
]
|
|
|
|
| 1149 |
|
| 1150 |
prev_btn.click(
|
| 1151 |
fn=handle_prev,
|
|
|
|
| 1176 |
|
| 1177 |
reset_btn.click(
|
| 1178 |
fn=on_generate_questions,
|
| 1179 |
+
inputs=[text_input, difficulty_level, temperature],
|
| 1180 |
outputs=[
|
| 1181 |
question_display,
|
| 1182 |
question_box,
|
|
|
|
| 1190 |
view_cert_btn
|
| 1191 |
]
|
| 1192 |
)
|
| 1193 |
+
|
| 1194 |
view_cert_btn.click(
|
| 1195 |
fn=show_certificate_tab,
|
| 1196 |
outputs=[cert_tab, course_name, tabs] # Add course_name to outputs
|