Spaces:
Sleeping
Sleeping
Update quiz_processing.py
Browse files- quiz_processing.py +30 -3
quiz_processing.py
CHANGED
@@ -229,6 +229,9 @@ def analyze_document(text, gemini_api_key, claude_api_key, course_name, section_
|
|
229 |
try:
|
230 |
start_time = time.time()
|
231 |
text_parts = split_text_by_tokens(text)
|
|
|
|
|
|
|
232 |
|
233 |
all_results = {
|
234 |
"course_info": {
|
@@ -241,6 +244,25 @@ def analyze_document(text, gemini_api_key, claude_api_key, course_name, section_
|
|
241 |
segment_counter = 1
|
242 |
|
243 |
for part in text_parts:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
analysis = segment_and_analyze_text(
|
245 |
text,
|
246 |
gemini_api_key,
|
@@ -250,7 +272,7 @@ def analyze_document(text, gemini_api_key, claude_api_key, course_name, section_
|
|
250 |
section_name=section_name,
|
251 |
lesson_name=lesson_name
|
252 |
)
|
253 |
-
|
254 |
if "segments" in analysis:
|
255 |
for segment in analysis["segments"]:
|
256 |
segment["segment_number"] = segment_counter
|
@@ -261,9 +283,14 @@ def analyze_document(text, gemini_api_key, claude_api_key, course_name, section_
|
|
261 |
total_time = end_time - start_time
|
262 |
print(f"Total quiz processing time: {total_time:.2f}s")
|
263 |
|
264 |
-
|
265 |
-
|
|
|
266 |
|
|
|
|
|
|
|
|
|
267 |
json_path = tempfile.mktemp(suffix='.json')
|
268 |
with open(json_path, 'w', encoding='utf-8') as json_file:
|
269 |
json.dump(all_results, json_file, indent=2)
|
|
|
229 |
try:
|
230 |
start_time = time.time()
|
231 |
text_parts = split_text_by_tokens(text)
|
232 |
+
|
233 |
+
input_tokens = 0
|
234 |
+
output_tokens = 0
|
235 |
|
236 |
all_results = {
|
237 |
"course_info": {
|
|
|
244 |
segment_counter = 1
|
245 |
|
246 |
for part in text_parts:
|
247 |
+
if language == "Uzbek" and claude_api_key:
|
248 |
+
from prompts import ANALYSIS_PROMPT_TEMPLATE_CLAUDE
|
249 |
+
prompt_template = ANALYSIS_PROMPT_TEMPLATE_CLAUDE
|
250 |
+
else:
|
251 |
+
from prompts import ANALYSIS_PROMPT_TEMPLATE_GEMINI
|
252 |
+
prompt_template = ANALYSIS_PROMPT_TEMPLATE_GEMINI
|
253 |
+
|
254 |
+
# Format the prompt with actual values
|
255 |
+
actual_prompt = prompt_template.format(
|
256 |
+
course_name=course_name,
|
257 |
+
section_name=section_name,
|
258 |
+
lesson_name=lesson_name,
|
259 |
+
text=part
|
260 |
+
)
|
261 |
+
|
262 |
+
prompt_tokens = len(tokenizer.encode(actual_prompt))
|
263 |
+
input_tokens += prompt_tokens
|
264 |
+
|
265 |
+
|
266 |
analysis = segment_and_analyze_text(
|
267 |
text,
|
268 |
gemini_api_key,
|
|
|
272 |
section_name=section_name,
|
273 |
lesson_name=lesson_name
|
274 |
)
|
275 |
+
|
276 |
if "segments" in analysis:
|
277 |
for segment in analysis["segments"]:
|
278 |
segment["segment_number"] = segment_counter
|
|
|
283 |
total_time = end_time - start_time
|
284 |
print(f"Total quiz processing time: {total_time:.2f}s")
|
285 |
|
286 |
+
formatted_output = format_quiz_for_display(all_results)
|
287 |
+
output_tokens = len(tokenizer.encode(formatted_output))
|
288 |
+
|
289 |
|
290 |
+
token_info = f"Input tokens: {input_tokens}\nOutput tokens: {output_tokens}\nTotal tokens: {input_tokens + output_tokens}\n"
|
291 |
+
formatted_text = format_quiz_for_display(all_results)
|
292 |
+
formatted_text = f"Total Processing time: {total_time:.2f}s\n{token_info}\n" + formatted_text
|
293 |
+
|
294 |
json_path = tempfile.mktemp(suffix='.json')
|
295 |
with open(json_path, 'w', encoding='utf-8') as json_file:
|
296 |
json.dump(all_results, json_file, indent=2)
|