not-lain commited on
Commit
8b27eff
·
verified ·
1 Parent(s): b20c417

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -1,13 +1,10 @@
1
  import os
2
- from datetime import datetime
3
  import random
4
 
5
- import pandas as pd
6
- from huggingface_hub import HfApi, hf_hub_download, Repository, whoami
7
- from huggingface_hub.repocard import metadata_load
8
 
9
  import gradio as gr
10
- from datasets import load_dataset, Dataset
11
 
12
  from data_to_parquet import to_parquet
13
 
@@ -17,12 +14,6 @@ EXAM_PASSING_SCORE = os.getenv("EXAM_PASSING_SCORE") or 0.7
17
 
18
  ds = load_dataset(EXAM_DATASET_ID, split="train")
19
 
20
- DATASET_REPO_URL = "https://huggingface.co/datasets/agents-course/certificates"
21
- CERTIFIED_USERS_FILENAME = "certified_students.csv"
22
- CERTIFIED_USERS_DIR = "certificates"
23
- repo = Repository(
24
- local_dir=CERTIFIED_USERS_DIR, clone_from=DATASET_REPO_URL, use_auth_token=os.getenv("HF_TOKEN")
25
- )
26
  upload_api = HfApi(token=os.getenv("HF_TOKEN"))
27
  # Convert dataset to a list of dicts and randomly sort
28
  quiz_data = ds.to_pandas().to_dict("records")
@@ -86,20 +77,28 @@ def push_results_to_hub(user_answers, token: gr.OAuthToken | None):
86
  gr.Warning(
87
  f"Score {grade:.1%} below passing threshold of {float(EXAM_PASSING_SCORE):.1%}"
88
  )
89
- return
90
 
91
  gr.Info("Submitting answers to the Hub. Please wait...", duration=2)
92
 
93
  user_info = whoami(token=token.token)
94
- repo_id = f"{EXAM_DATASET_ID}_student_scores"
95
- # TODO:
96
  # check if username already has "username.parquet" in the dataset and download that (or read values directly from dataset viewer if possible)
97
  # instead of replacing the values check if the new score is better than the old one
98
- to_parquet(upload_api,"not-lain/testing-my-upload",user_info["name"],grade,0,0,0)
99
-
100
- gr.Success(f"Your responses have been submitted to the Hub! Final grade: {grade:.1%}")
101
-
 
 
 
 
 
 
102
 
 
 
 
103
 
104
 
105
  def handle_quiz(question_idx, user_answers, selected_answer, is_start):
 
1
  import os
 
2
  import random
3
 
4
+ from huggingface_hub import HfApi, whoami
 
 
5
 
6
  import gradio as gr
7
+ from datasets import load_dataset
8
 
9
  from data_to_parquet import to_parquet
10
 
 
14
 
15
  ds = load_dataset(EXAM_DATASET_ID, split="train")
16
 
 
 
 
 
 
 
17
  upload_api = HfApi(token=os.getenv("HF_TOKEN"))
18
  # Convert dataset to a list of dicts and randomly sort
19
  quiz_data = ds.to_pandas().to_dict("records")
 
77
  gr.Warning(
78
  f"Score {grade:.1%} below passing threshold of {float(EXAM_PASSING_SCORE):.1%}"
79
  )
80
+ return # do not continue
81
 
82
  gr.Info("Submitting answers to the Hub. Please wait...", duration=2)
83
 
84
  user_info = whoami(token=token.token)
85
+ # TODO:
 
86
  # check if username already has "username.parquet" in the dataset and download that (or read values directly from dataset viewer if possible)
87
  # instead of replacing the values check if the new score is better than the old one
88
+ to_parquet(
89
+ upload_api, # api
90
+ "agents-course/students-data", # repo_id
91
+ user_info["name"], # username
92
+ grade, # unit1 score
93
+ 0.0, # unit2 score
94
+ 0.0, # unit3 score
95
+ 0.0, # unit4 score
96
+ 0, # already certified or not
97
+ )
98
 
99
+ gr.Success(
100
+ f"Your responses have been submitted to the Hub! Final grade: {grade:.1%}"
101
+ )
102
 
103
 
104
  def handle_quiz(question_idx, user_answers, selected_answer, is_start):