Spaces:
Sleeping
Sleeping
Update quiz_processing.py
Browse files- quiz_processing.py +6 -5
quiz_processing.py
CHANGED
|
@@ -156,13 +156,17 @@ def segment_and_analyze_text(text: str, gemini_api_key: str, claude_api_key: str
|
|
| 156 |
max_retries=3
|
| 157 |
)
|
| 158 |
|
| 159 |
-
|
| 160 |
course_name=course_name,
|
| 161 |
section_name=section_name,
|
| 162 |
lesson_name=lesson_name,
|
| 163 |
text=text
|
| 164 |
)
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
try:
|
| 167 |
messages = [
|
| 168 |
{"role": "system", "content": SYSTEM_PROMPT},
|
|
@@ -318,10 +322,7 @@ def analyze_document(text, gemini_api_key, claude_api_key, course_name, section_
|
|
| 318 |
formatted_text = format_quiz_for_display(all_results, language)
|
| 319 |
formatted_text = f"Total Processing time: {total_time:.2f}s\n{token_info}\n" + formatted_text
|
| 320 |
|
| 321 |
-
output_tokens = len(tokenizer.encode(formatted_output))
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
# Create temporary files for JSON and text output
|
| 325 |
json_path = tempfile.mktemp(suffix='.json')
|
| 326 |
with open(json_path, 'w', encoding='utf-8') as json_file:
|
| 327 |
json.dump(all_results, json_file, indent=2)
|
|
|
|
| 156 |
max_retries=3
|
| 157 |
)
|
| 158 |
|
| 159 |
+
base_prompt = ANALYSIS_PROMPT_TEMPLATE_GEMINI.format(
|
| 160 |
course_name=course_name,
|
| 161 |
section_name=section_name,
|
| 162 |
lesson_name=lesson_name,
|
| 163 |
text=text
|
| 164 |
)
|
| 165 |
|
| 166 |
+
language_instruction = f"\nIMPORTANT: Generate ALL content (including topic names, key concepts, summaries, and quiz questions) in {language} language."
|
| 167 |
+
prompt = base_prompt + language_instruction
|
| 168 |
+
|
| 169 |
+
|
| 170 |
try:
|
| 171 |
messages = [
|
| 172 |
{"role": "system", "content": SYSTEM_PROMPT},
|
|
|
|
| 322 |
formatted_text = format_quiz_for_display(all_results, language)
|
| 323 |
formatted_text = f"Total Processing time: {total_time:.2f}s\n{token_info}\n" + formatted_text
|
| 324 |
|
| 325 |
+
output_tokens = len(tokenizer.encode(formatted_output))
|
|
|
|
|
|
|
|
|
|
| 326 |
json_path = tempfile.mktemp(suffix='.json')
|
| 327 |
with open(json_path, 'w', encoding='utf-8') as json_file:
|
| 328 |
json.dump(all_results, json_file, indent=2)
|