Spaces:
Runtime error
Runtime error
Commit ·
3d7abcf
0
Parent(s):
Duplicate from ThomasSimonini/Check-my-progress-Deep-RL-Course
Browse filesCo-authored-by: Thomas Simonini <ThomasSimonini@users.noreply.huggingface.co>
Files changed (4)
- .gitattributesAdded+34
- README.mdAdded+13
- app.pyAdded+285
- utils.pyAdded+16
12345678910111213141516171819202122232425262728293031323334*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text12345678910111213---title: Check My Progress Deep RL Courseemoji: 👀colorFrom: yellowcolorTo: purplesdk: gradiosdk_version: 3.16.0app_file: app.pypinned: falseduplicated_from: ThomasSimonini/Check-my-progress-Deep-RL-Course---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285import gradio as grfrom huggingface_hub import HfApi, hf_hub_downloadfrom huggingface_hub.repocard import metadata_load
import pandas as pd
from utils import *
api = HfApi()
def get_user_models(hf_username, env_tag, lib_tag): """ List the Reinforcement Learning models from user given environment and lib :param hf_username: User HF username :param env_tag: Environment tag :param lib_tag: Library tag """ api = HfApi() models = api.list_models(author=hf_username, filter=["reinforcement-learning", env_tag, lib_tag])
user_model_ids = [x.modelId for x in models] return user_model_ids
def get_user_sf_models(hf_username, env_tag, lib_tag): api = HfApi() models_sf = [] models = api.list_models(author=hf_username, filter=["reinforcement-learning", lib_tag])
user_model_ids = [x.modelId for x in models]
for model in user_model_ids: meta = get_metadata(model) if meta is None: continue result = meta["model-index"][0]["results"][0]["dataset"]["name"] if result == env_tag: models_sf.append(model) return models_sf
def get_metadata(model_id): """ Get model metadata (contains evaluation data) :param model_id """ try: readme_path = hf_hub_download(model_id, filename="README.md") return metadata_load(readme_path) except requests.exceptions.HTTPError: # 404 README.md not found return None
def parse_metrics_accuracy(meta): """ Get model results and parse it :param meta: model metadata """ if "model-index" not in meta: return None result = meta["model-index"][0]["results"] metrics = result[0]["metrics"] accuracy = metrics[0]["value"] return accuracy
def parse_rewards(accuracy): """ Parse mean_reward and std_reward :param accuracy: model results """ default_std = -1000 default_reward= -1000 if accuracy != None: accuracy = str(accuracy) parsed = accuracy.split(' +/- ') if len(parsed)>1: mean_reward = float(parsed[0]) std_reward = float(parsed[1]) elif len(parsed)==1: #only mean reward mean_reward = float(parsed[0]) std_reward = float(0) else: mean_reward = float(default_std) std_reward = float(default_reward) else: mean_reward = float(default_std) std_reward = float(default_reward) return mean_reward, std_reward
def calculate_best_result(user_model_ids): """ Calculate the best results of a unit best_result = mean_reward - std_reward :param user_model_ids: RL models of a user """ best_result = -1000 best_model_id = "" for model in user_model_ids: meta = get_metadata(model) if meta is None: continue accuracy = parse_metrics_accuracy(meta) mean_reward, std_reward = parse_rewards(accuracy) result = mean_reward - std_reward if result > best_result: best_result = result best_model_id = model return best_result, best_model_id
def check_if_passed(model): """ Check if result >= baseline to know if you pass :param model: user model """ if model["best_result"] >= model["min_result"]: model["passed_"] = True
def certification(hf_username): results_certification = [ { "unit": "Unit 1", "env": "LunarLander-v2", "library": "stable-baselines3", "min_result": 200, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 2", "env": "Taxi-v3", "library": "q-learning", "min_result": 4, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 3", "env": "SpaceInvadersNoFrameskip-v4", "library": "stable-baselines3", "min_result": 200, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 4", "env": "CartPole-v1", "library": "reinforce", "min_result": 350, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 4", "env": "Pixelcopter-PLE-v0", "library": "reinforce", "min_result": 5, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 5", "env": "ML-Agents-SnowballTarget", "library": "ml-agents", "min_result": -100, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 5", "env": "ML-Agents-Pyramids", "library": "ml-agents", "min_result": -100, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 6", "env": "AntBulletEnv-v0", "library": "stable-baselines3", "min_result": 650, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 6", "env": "PandaReachDense-v2", "library": "stable-baselines3", "min_result": -3.5, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 7", "env": "ML-Agents-SoccerTwos", "library": "ml-agents", "min_result": -100, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 8 PI", "env": "LunarLander-v2", "library": "deep-rl-course", "min_result": -500, "best_result": 0, "best_model_id": "", "passed_": False }, { "unit": "Unit 8 PII", "env": "doom_health_gathering_supreme", "library": "sample-factory", "min_result": 5, "best_result": 0, "best_model_id": "", "passed_": False }, ] for unit in results_certification: if unit["unit"] != "Unit 8 PII": # Get user model user_models = get_user_models(hf_username, unit['env'], unit['library']) # For sample factory vizdoom we don't have env tag for now else: user_models = get_user_sf_models(hf_username, unit['env'], unit['library'])
# Calculate the best result and get the best_model_id best_result, best_model_id = calculate_best_result(user_models)
# Save best_result and best_model_id unit["best_result"] = best_result unit["best_model_id"] = make_clickable_model(best_model_id)
# Based on best_result do we pass the unit? check_if_passed(unit) unit["passed"] = pass_emoji(unit["passed_"]) print(results_certification) df = pd.DataFrame(results_certification) df = df[['passed', 'unit', 'env', 'min_result', 'best_result', 'best_model_id']] return df
with gr.Blocks() as demo: gr.Markdown(f""" # 🏆 Check your progress in the Deep Reinforcement Learning Course 🏆 You can check your progress here. - To get a certificate of completion, you must **pass 80% of the assignments before June 1st 2023**. - To get an honors certificate, you must **pass 100% of the assignments before June 1st 2023**.
To pass an assignment your model result (mean_reward - std_reward) must be >= min_result
**When min_result = -100 it means that you just need to push a model to pass this hands-on. No need to reach a certain result.** Just type your Hugging Face Username 🤗 (in my case ThomasSimonini) """) hf_username = gr.Textbox(placeholder="ThomasSimonini", label="Your Hugging Face Username") #email = gr.Textbox(placeholder="thomas.simonini@huggingface.co", label="Your Email (to receive your certificate)") check_progress_button = gr.Button(value="Check my progress") output = gr.components.Dataframe(value= certification(hf_username), headers=["Pass?", "Unit", "Environment", "Baseline", "Your best result", "Your best model id"], datatype=["markdown", "markdown", "markdown", "number", "number", "markdown", "bool"]) check_progress_button.click(fn=certification, inputs=hf_username, outputs=output)
demo.launch()12345678910111213141516# Based on Omar Sanseviero work# Make model clickable linkdef make_clickable_model(model_name): # remove user from model name model_name_show = ' '.join(model_name.split('/')[1:])
link = "https://huggingface.co/" + model_name return f'<a target="_blank" href="{link}">{model_name_show}</a>'
def pass_emoji(passed): print("PASSED", passed) if passed is True: passed = "✅" else: passed = "❌" return passed.gitattributesAdded+34
README.mdAdded+13
app.pyAdded+285
utils.pyAdded+16