gabejavitt commited on
Commit
132145a
Β·
verified Β·
1 Parent(s): 1726a93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -83
app.py CHANGED
@@ -1845,89 +1845,6 @@ except Exception as e:
1845
  # =============================================================================
1846
  # RUN AND SUBMIT FUNCTION
1847
  # =============================================================================
1848
- def load_answer_sheet(filepath: str = "answer_sheet.json") -> Dict[str, str]:
1849
- """Load the answer sheet from a JSON file"""
1850
- try:
1851
- if os.path.exists(filepath):
1852
- with open(filepath, 'r', encoding='utf-8') as f:
1853
- answers = json.load(f)
1854
- print(f"βœ… Loaded answer sheet with {len(answers)} answers from {filepath}")
1855
- return answers
1856
- else:
1857
- print(f"⚠️ Answer sheet not found at {filepath}")
1858
- return {}
1859
- except Exception as e:
1860
- print(f"❌ Error loading answer sheet: {e}")
1861
- return {}
1862
-
1863
-
1864
- def check_answer_correctness(submitted: str, correct: str) -> Tuple[bool, str]:
1865
- """
1866
- Check if submitted answer matches correct answer with fuzzy matching
1867
- Returns: (is_correct, feedback_message)
1868
- """
1869
- # Normalize both answers
1870
- submitted_norm = submitted.strip().lower()
1871
- correct_norm = correct.strip().lower()
1872
-
1873
- # Exact match
1874
- if submitted_norm == correct_norm:
1875
- return True, "βœ… EXACT MATCH"
1876
-
1877
- # Remove common punctuation and check again
1878
- import string
1879
- submitted_clean = submitted_norm.translate(str.maketrans('', '', string.punctuation))
1880
- correct_clean = correct_norm.translate(str.maketrans('', '', string.punctuation))
1881
-
1882
- if submitted_clean == correct_clean:
1883
- return True, "βœ… MATCH (punctuation difference)"
1884
-
1885
- # Check if it's a number formatting issue
1886
- try:
1887
- # Try to parse as numbers
1888
- submitted_num = float(submitted_clean.replace(',', '').replace('$', ''))
1889
- correct_num = float(correct_clean.replace(',', '').replace('$', ''))
1890
- if abs(submitted_num - correct_num) < 0.01: # Allow small floating point differences
1891
- return True, "βœ… MATCH (numeric equivalence)"
1892
- except (ValueError, AttributeError):
1893
- pass
1894
-
1895
- # Check if submitted answer contains correct answer (for list-type answers)
1896
- if ',' in correct_norm:
1897
- correct_items = set([item.strip() for item in correct_norm.split(',')])
1898
- submitted_items = set([item.strip() for item in submitted_norm.split(',')])
1899
-
1900
- if correct_items == submitted_items:
1901
- return True, "βœ… MATCH (item order difference)"
1902
-
1903
- missing_items = correct_items - submitted_items
1904
- extra_items = submitted_items - correct_items
1905
-
1906
- if missing_items and not extra_items:
1907
- return False, f"❌ MISSING: {', '.join(missing_items)}"
1908
- elif extra_items and not missing_items:
1909
- return False, f"❌ EXTRA: {', '.join(extra_items)}"
1910
- elif missing_items and extra_items:
1911
- return False, f"❌ MISSING: {', '.join(missing_items)} | EXTRA: {', '.join(extra_items)}"
1912
-
1913
- # Check case-insensitive substring match
1914
- if submitted_norm in correct_norm or correct_norm in submitted_norm:
1915
- return False, f"❌ PARTIAL MATCH (submitted: '{submitted}' | correct: '{correct}')"
1916
-
1917
- return False, f"❌ WRONG (submitted: '{submitted}' | correct: '{correct}')"
1918
-
1919
-
1920
- def create_answer_sheet_template(questions: List[Dict], filepath: str = "answer_sheet.json"):
1921
- """Create an answer sheet template from questions"""
1922
- answer_template = {}
1923
- for q in questions:
1924
- answer_template[q['task_id']] = ""
1925
-
1926
- with open(filepath, 'w', encoding='utf-8') as f:
1927
- json.dump(answer_template, f, indent=2)
1928
-
1929
- print(f"βœ… Created answer sheet template at {filepath}")
1930
- print(f" Please fill in the correct answers for {len(answer_template)} questions")
1931
 
1932
  def run_and_submit_all(profile: gr.OAuthProfile | None):
1933
  """
 
1845
  # =============================================================================
1846
  # RUN AND SUBMIT FUNCTION
1847
  # =============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1848
 
1849
  def run_and_submit_all(profile: gr.OAuthProfile | None):
1850
  """