import%20marimo%0A%0A__generated_with%20%3D%20%220.13.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20polars%20as%20pl%0A%20%20%20%20from%20rich%20import%20print%0A%20%20%20%20return%20(pl%2C)%0A%0A%0A%40app.cell%0Adef%20_(pl)%3A%0A%20%20%20%20old_dataset%20%3D%20pl.read_csv('hf%3A%2F%2Fdatasets%2Ferwanlc%2Fcocktails_recipe%2Ftrain.csv').drop_nulls()%0A%20%20%20%20old_dataset%0A%20%20%20%20return%20(old_dataset%2C)%0A%0A%0A%40app.cell%0Adef%20_(old_dataset)%3A%0A%20%20%20%20import%20ast%0A%20%20%20%20from%20pydantic%20import%20BaseModel%0A%0A%20%20%20%20class%20Ingredient(BaseModel)%3A%0A%20%20%20%20%20%20%20%20amount%3A%20str%0A%20%20%20%20%20%20%20%20name%3A%20str%0A%0A%20%20%20%20class%20Recipe(BaseModel)%3A%0A%20%20%20%20%20%20%20%20title%3A%20str%0A%20%20%20%20%20%20%20%20glass%3A%20str%0A%20%20%20%20%20%20%20%20garnish%3A%20str%0A%20%20%20%20%20%20%20%20recipe%3A%20str%0A%20%20%20%20%20%20%20%20ingredients%3A%20list%5BIngredient%5D%0A%0A%20%20%20%20def%20extract_ingredients(raw%3A%20str)%20-%3E%20list%5BIngredient%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Extract%20ingredients%20from%20a%20raw%20string%20representing%20a%20list%20of%20lists.%0A%20%20%20%20%20%20%20%20Each%20inner%20list%20should%20contain%20two%20elements%3A%20a%20quantity%20token%20and%20an%20ingredient%20name.%0A%0A%20%20%20%20%20%20%20%20The%20raw%20data%20is%20expected%20to%20be%20a%20one-line%20string.%20%0A%20%20%20%20%20%20%20%20Example%3A%0A%20%20%20%20%20%20%20%20'%5B%5B%222%201%E2%81%842%20test%22%2C%20%22Sugar%22%5D%2C%20%5B%222%201%E2%81%842%22%2C%20%22Sugar%22%5D%2C%5B%222%20dried%22%2C%20%22Star%20anise%22%5D%2C%20...%20%5D'%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20ingredients_list%3A%20list%5Blist%5Bstr%5D%5D%20%3D%20ast.literal_eval(raw)%0A%20%20%20%20%20%20%20%20extracted%3A%20list%5BIngredient%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20for%20ingredient%20in%20ingredients_list%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20ingr%3A%20Ingredient%20%3D%20Ingredient(amount%3Dingredient%5B0%5D%2C%20name%3Dingredient%5B1%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20extracted.append(ingr)%0A%20%20%20%20%20%20%20%20return%20extracted%0A%0A%0A%20%20%20%20extract_ingredients(old_dataset.item(0%2C%20'ingredients'))%0A%20%20%20%20return%20Recipe%2C%20extract_ingredients%0A%0A%0A%40app.cell%0Adef%20_(Recipe%2C%20extract_ingredients%2C%20old_dataset)%3A%0A%20%20%20%20new_dataset_python%3A%20list%5BRecipe%5D%20%3D%20%5B%5D%0A%0A%20%20%20%20for%20row%20in%20old_dataset.iter_rows(named%3DTrue)%3A%0A%20%20%20%20%20%20%20%20_ingr%20%3D%20extract_ingredients(row%5B'ingredients'%5D)%0A%20%20%20%20%20%20%20%20_recipe%20%3D%20Recipe(%0A%20%20%20%20%20%20%20%20%20%20%20%20title%3Drow%5B'title'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20glass%3Drow%5B'glass'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20garnish%3Drow%5B'garnish'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20recipe%3Drow%5B'recipe'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ingredients%3D_ingr%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20new_dataset_python.append(_recipe)%0A%0A%20%20%20%20len(new_dataset_python)%0A%20%20%20%20return%20(new_dataset_python%2C)%0A%0A%0A%40app.cell%0Adef%20_(new_dataset_python%2C%20pl)%3A%0A%20%20%20%20new_dataset_polars%20%3D%20pl.DataFrame(new_dataset_python)%0A%20%20%20%20new_dataset_polars%0A%20%20%20%20return%20(new_dataset_polars%2C)%0A%0A%0A%40app.cell%0Adef%20_(new_dataset_polars)%3A%0A%20%20%20%20from%20datasets%20import%20Dataset%0A%0A%20%20%20%20new_dataset_hf%20%3D%20Dataset.from_polars(new_dataset_polars)%0A%20%20%20%20new_dataset_hf%0A%20%20%20%20return%20(Dataset%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20new_dataset_hf.push_to_hub('toiletsandpaper%2Fdraft_fix'%2C%20private%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Dataset)%3A%0A%20%20%20%20from%20datasets%20import%20load_dataset%0A%0A%20%20%20%20pushed_dataset%20%3D%20load_dataset(%22erwanlc%2Fcocktails_recipe%22%2C%20revision%3D%22pr%2F3%22%2C%20split%3D'train')%0A%20%20%20%20Dataset.to_polars(pushed_dataset)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
378e4c314a61b9a7ab24fdfe62d1d33751b1a12e8c732b4d5e136b4d817bcf34