yamanavijayavardhan commited on
Commit
4c684d1
·
1 Parent(s): 06e2e41

fix answer print

Browse files
Files changed (1) hide show
  1. main.py +19 -83
main.py CHANGED
@@ -458,11 +458,27 @@ def compute_marks():
458
  "message": "Starting text extraction..."
459
  })
460
  extracted_text = extract_text_from_image(filepath)
461
- log_print("Text extraction completed")
 
 
 
 
 
462
  notification_queue.put({
463
- "type": "success",
464
- "message": "Text extraction completed"
 
 
 
 
 
 
 
 
 
 
465
  })
 
466
  except Exception as e:
467
  error_msg = str(e).encode('ascii', 'ignore').decode('ascii')
468
  log_print(f"Text extraction error: {error_msg}", "ERROR")
@@ -477,86 +493,6 @@ def compute_marks():
477
  })
478
  continue
479
 
480
- # Clean the extracted text for JSON
481
- extracted_text = extracted_text.encode('ascii', 'ignore').decode('ascii')
482
-
483
- # Find best matching answer
484
- best_score = 0
485
- best_answer_index = 0
486
-
487
- for i, correct_answer in enumerate(correct_answers):
488
- try:
489
- # Clean the correct answer for comparison
490
- clean_correct_answer = correct_answer.encode('ascii', 'ignore').decode('ascii')
491
-
492
- # Calculate similarity scores
493
- log_print("Starting similarity score calculations...")
494
- notification_queue.put({
495
- "type": "info",
496
- "message": "Starting similarity score calculations..."
497
- })
498
-
499
- log_print(f"Calculating scores for answer {i+1}...")
500
- notification_queue.put({
501
- "type": "info",
502
- "message": f"Calculating scores for answer {i+1}..."
503
- })
504
-
505
- semantic_score = question_vector_sentence(extracted_text, clean_correct_answer)
506
- word_score = question_vector_word(extracted_text, clean_correct_answer)
507
- tfidf_score = tfidf_answer_score(extracted_text, clean_correct_answer, max_tfidf)
508
- ft_score = fasttext_similarity(extracted_text, clean_correct_answer)
509
- llm_marks = llm_score(clean_correct_answer, extracted_text)
510
-
511
- # Calculate final score
512
- final_score = (
513
- semantic_score * 0.3 +
514
- word_score * 0.2 +
515
- tfidf_score * 0.2 +
516
- ft_score * 0.15 +
517
- llm_marks * 0.15
518
- )
519
-
520
- if final_score > best_score:
521
- best_score = final_score
522
- best_answer_index = i
523
-
524
- except Exception as e:
525
- error_msg = str(e).encode('ascii', 'ignore').decode('ascii')
526
- log_print(f"Error calculating scores: {error_msg}", "ERROR")
527
- notification_queue.put({
528
- "type": "error",
529
- "message": f"Error calculating scores: {error_msg}"
530
- })
531
- continue
532
-
533
- # Send individual scores to frontend
534
- notification_queue.put({
535
- "type": "info",
536
- "message": f"Individual scores for {filename}:",
537
- "data": {
538
- "semantic": semantic_score,
539
- "word": word_score,
540
- "tfidf": tfidf_score,
541
- "fasttext": ft_score,
542
- "llm": llm_marks
543
- }
544
- })
545
-
546
- # Add result
547
- results.append({
548
- "filename": filename,
549
- "scores": {
550
- "semantic": semantic_score,
551
- "word": word_score,
552
- "tfidf": tfidf_score,
553
- "fasttext": ft_score,
554
- "llm": llm_marks,
555
- "final": best_score
556
- },
557
- "best_match_index": best_answer_index
558
- })
559
-
560
  # Clean up temporary file
561
  try:
562
  os.remove(filepath)
 
458
  "message": "Starting text extraction..."
459
  })
460
  extracted_text = extract_text_from_image(filepath)
461
+
462
+ # Log the extracted text
463
+ log_print(f"Extracted text from {filename}:")
464
+ log_print(extracted_text)
465
+
466
+ # Send extracted text to frontend
467
  notification_queue.put({
468
+ "type": "info",
469
+ "message": f"Extracted text from {filename}:",
470
+ "data": {
471
+ "extracted_text": extracted_text
472
+ }
473
+ })
474
+
475
+ # For debugging, just return the extracted text without scoring
476
+ results.append({
477
+ "filename": filename,
478
+ "extracted_text": extracted_text,
479
+ "scores": None
480
  })
481
+
482
  except Exception as e:
483
  error_msg = str(e).encode('ascii', 'ignore').decode('ascii')
484
  log_print(f"Text extraction error: {error_msg}", "ERROR")
 
493
  })
494
  continue
495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  # Clean up temporary file
497
  try:
498
  os.remove(filepath)