-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add credentials.py to get user token
- Loading branch information
Showing
3 changed files
with
246 additions
and
13 deletions.
There are no files selected for viewing
234 changes: 234 additions & 0 deletions
234
examples/notebooks/Uploading Models to HuggingFace.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"metadata": {}, | ||
"cell_type": "raw", | ||
"source": [ | ||
"{\n", | ||
" \"cells\": [\n", | ||
" {\n", | ||
" \"cell_type\": \"markdown\",\n", | ||
" \"source\": [\n", | ||
" \"# Patra Integration with Hugging Face\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"[](https://colab.research.google.com/github/Data-to-Insight-Center/patra-toolkit/blob/main/examples/notebooks/HuggingFace_Example.ipynb)\\n\"\n", | ||
" ],\n", | ||
" \"metadata\": {\n", | ||
" \"id\": \"KFXMTro-ne3-\"\n", | ||
" },\n", | ||
" \"id\": \"KFXMTro-ne3-\"\n", | ||
" },\n", | ||
" {\n", | ||
" \"cell_type\": \"code\",\n", | ||
" \"source\": \"!pip install patra-toolkit -e .\",\n", | ||
" \"metadata\": {\n", | ||
" \"collapsed\": true,\n", | ||
" \"colab\": {\n", | ||
" \"base_uri\": \"https://localhost:8080/\"\n", | ||
" },\n", | ||
" \"id\": \"Gm1pg-KpnfaJ\",\n", | ||
" \"outputId\": \"798399ae-2826-4940-9e78-1714e568cd51\",\n", | ||
" \"ExecuteTime\": {\n", | ||
" \"end_time\": \"2025-02-13T01:01:43.915193Z\",\n", | ||
" \"start_time\": \"2025-02-13T01:01:43.314247Z\"\n", | ||
" }\n", | ||
" },\n", | ||
" \"id\": \"Gm1pg-KpnfaJ\",\n", | ||
" \"outputs\": [\n", | ||
" {\n", | ||
" \"name\": \"stdout\",\n", | ||
" \"output_type\": \"stream\",\n", | ||
" \"text\": [\n", | ||
" \"Obtaining file:///Users/neeleshkarthikeyan/d2i/patra-toolkit/examples/notebooks\\r\\n\",\n", | ||
" \"\\u001B[31mERROR: file:///Users/neeleshkarthikeyan/d2i/patra-toolkit/examples/notebooks does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.\\u001B[0m\\u001B[31m\\r\\n\",\n", | ||
" \"\\u001B[0m\\r\\n\",\n", | ||
" \"\\u001B[1m[\\u001B[0m\\u001B[34;49mnotice\\u001B[0m\\u001B[1;39;49m]\\u001B[0m\\u001B[39;49m A new release of pip is available: \\u001B[0m\\u001B[31;49m23.2.1\\u001B[0m\\u001B[39;49m -> \\u001B[0m\\u001B[32;49m25.0.1\\u001B[0m\\r\\n\",\n", | ||
" \"\\u001B[1m[\\u001B[0m\\u001B[34;49mnotice\\u001B[0m\\u001B[1;39;49m]\\u001B[0m\\u001B[39;49m To update, run: \\u001B[0m\\u001B[32;49mpip install --upgrade pip\\u001B[0m\\r\\n\"\n", | ||
" ]\n", | ||
" }\n", | ||
" ],\n", | ||
" \"execution_count\": 10\n", | ||
" },\n", | ||
" {\n", | ||
" \"cell_type\": \"code\",\n", | ||
" \"source\": [\n", | ||
" \"import torchvision.models as models\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"model = models.resnet50(pretrained=True)\\n\"\n", | ||
" ],\n", | ||
" \"metadata\": {\n", | ||
" \"colab\": {\n", | ||
" \"base_uri\": \"https://localhost:8080/\"\n", | ||
" },\n", | ||
" \"id\": \"3_qN6LTjAVOT\",\n", | ||
" \"outputId\": \"501dd56f-231c-4845-94b2-559d0549c5d2\",\n", | ||
" \"ExecuteTime\": {\n", | ||
" \"end_time\": \"2025-02-13T01:01:44.821461Z\",\n", | ||
" \"start_time\": \"2025-02-13T01:01:44.376241Z\"\n", | ||
" }\n", | ||
" },\n", | ||
" \"id\": \"3_qN6LTjAVOT\",\n", | ||
" \"outputs\": [],\n", | ||
" \"execution_count\": 11\n", | ||
" },\n", | ||
" {\n", | ||
" \"metadata\": {\n", | ||
" \"colab\": {\n", | ||
" \"base_uri\": \"https://localhost:8080/\"\n", | ||
" },\n", | ||
" \"id\": \"xwXQeWspo7kl\",\n", | ||
" \"outputId\": \"ab051b67-60cd-4f73-bab3-ac40e5ca31f2\",\n", | ||
" \"ExecuteTime\": {\n", | ||
" \"end_time\": \"2025-02-13T01:01:45.287450Z\",\n", | ||
" \"start_time\": \"2025-02-13T01:01:45.281271Z\"\n", | ||
" }\n", | ||
" },\n", | ||
" \"cell_type\": \"code\",\n", | ||
" \"source\": [\n", | ||
" \"from patra_toolkit import ModelCard, AIModel\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"# Initialize the Model Card\\n\",\n", | ||
" \"mc = ModelCard(\\n\",\n", | ||
" \" name=\\\"ResNet50 Image Classification Model\\\",\\n\",\n", | ||
" \" version=\\\"1.0\\\",\\n\",\n", | ||
" \" short_description=\\\"Pre-trained ResNet50 model from torchvision for image classification.\\\",\\n\",\n", | ||
" \" full_description=(\\n\",\n", | ||
" \" \\\"This ResNet50 model is pre-trained on ImageNet and can be used for a variety \\\"\\n\",\n", | ||
" \" \\\"of image classification tasks. It demonstrates the use of Patra Model Cards to \\\"\\n\",\n", | ||
" \" \\\"document model metadata, bias, and explainability metrics.\\\"\\n\",\n", | ||
" \" ),\\n\",\n", | ||
" \" keywords=\\\"ResNet50, image classification, pytorch, ImageNet, model card\\\",\\n\",\n", | ||
" \" author=\\\"Neelesh Karthikeyan\\\",\\n\",\n", | ||
" \" input_type=\\\"Image\\\",\\n\",\n", | ||
" \" category=\\\"classification\\\",\\n\",\n", | ||
" \" foundational_model=\\\"None\\\"\\n\",\n", | ||
" \")\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"# Define input and output data URLs\\n\",\n", | ||
" \"mc.input_data = 'https://huggingface.co/datasets/cifar10'\\n\",\n", | ||
" \"mc.output_data = 'https://huggingface.co/nkarthikeyan/ResNet50_Image_Classification_Model/blob/main/ResNet50_Image_Classification_Model.pt'\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"# Initialize AI Model details\\n\",\n", | ||
" \"ai_model = AIModel(\\n\",\n", | ||
" \" name=\\\"ResNet50 Image Classification Model\\\",\\n\",\n", | ||
" \" version=\\\"1.0\\\",\\n\",\n", | ||
" \" description=(\\n\",\n", | ||
" \" \\\"Pre-trained ResNet50 model from torchvision for image classification. \\\"\\n\",\n", | ||
" \" \\\"This model achieves approximately 76% top-1 accuracy on ImageNet.\\\"\\n\",\n", | ||
" \" ),\\n\",\n", | ||
" \" owner=\\\"Neelesh Karthikeyan\\\",\\n\",\n", | ||
" \" location='https://huggingface.co/nkarthikeyan/ResNet50_Image_Classification_Model/blob/main/ResNet50_Image_Classification_Model.pt',\\n\",\n", | ||
" \" license=\\\"Apache-2.0\\\",\\n\",\n", | ||
" \" framework=\\\"pytorch\\\",\\n\",\n", | ||
" \" model_type=\\\"cnn\\\",\\n\",\n", | ||
" \" test_accuracy=0.76\\n\",\n", | ||
" \")\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"ai_model.populate_model_structure(model)\\n\",\n", | ||
" \"mc.ai_model = ai_model\\n\",\n", | ||
" \"mc.populate_requirements()\\n\"\n", | ||
" ],\n", | ||
" \"id\": \"xwXQeWspo7kl\",\n", | ||
" \"outputs\": [],\n", | ||
" \"execution_count\": 12\n", | ||
" },\n", | ||
" {\n", | ||
" \"metadata\": {\n", | ||
" \"id\": \"y2Xfa42KqX9H\",\n", | ||
" \"colab\": {\n", | ||
" \"base_uri\": \"https://localhost:8080/\"\n", | ||
" },\n", | ||
" \"outputId\": \"4865c483-eaee-4da5-b58f-8a82fdcb145c\",\n", | ||
" \"ExecuteTime\": {\n", | ||
" \"end_time\": \"2025-02-13T01:01:46.431710Z\",\n", | ||
" \"start_time\": \"2025-02-13T01:01:46.049438Z\"\n", | ||
" }\n", | ||
" },\n", | ||
" \"cell_type\": \"code\",\n", | ||
" \"source\": [\n", | ||
" \"# Validate the Model Card\\n\",\n", | ||
" \"mc.validate()\\n\",\n", | ||
" \"\\n\",\n", | ||
" \"# Submit the Model Card\\n\",\n", | ||
" \"mc.submit(patra_server_url=\\\"http://10.20.227.55:5002\\\", model=model)\\n\"\n", | ||
" ],\n", | ||
" \"id\": \"y2Xfa42KqX9H\",\n", | ||
" \"outputs\": [\n", | ||
" {\n", | ||
" \"data\": {\n", | ||
" \"text/plain\": [\n", | ||
" \"{'error': 'Failed to submit model card: 500 Server Error: INTERNAL SERVER ERROR for url: http://10.20.227.55:5002/upload_mc'}\"\n", | ||
" ]\n", | ||
" },\n", | ||
" \"execution_count\": 13,\n", | ||
" \"metadata\": {},\n", | ||
" \"output_type\": \"execute_result\"\n", | ||
" }\n", | ||
" ],\n", | ||
" \"execution_count\": 13\n", | ||
" },\n", | ||
" {\n", | ||
" \"cell_type\": \"code\",\n", | ||
" \"source\": [],\n", | ||
" \"metadata\": {\n", | ||
" \"id\": \"wMuGP-ogrKdA\"\n", | ||
" },\n", | ||
" \"id\": \"wMuGP-ogrKdA\",\n", | ||
" \"execution_count\": null,\n", | ||
" \"outputs\": []\n", | ||
" }\n", | ||
" ],\n", | ||
" \"metadata\": {\n", | ||
" \"kernelspec\": {\n", | ||
" \"display_name\": \"Python 3\",\n", | ||
" \"language\": \"python\",\n", | ||
" \"name\": \"python3\"\n", | ||
" },\n", | ||
" \"language_info\": {\n", | ||
" \"codemirror_mode\": {\n", | ||
" \"name\": \"ipython\",\n", | ||
" \"version\": 2\n", | ||
" },\n", | ||
" \"file_extension\": \".py\",\n", | ||
" \"mimetype\": \"text/x-python\",\n", | ||
" \"name\": \"python\",\n", | ||
" \"nbconvert_exporter\": \"python\",\n", | ||
" \"pygments_lexer\": \"ipython2\",\n", | ||
" \"version\": \"2.7.6\"\n", | ||
" },\n", | ||
" \"colab\": {\n", | ||
" \"provenance\": []\n", | ||
" }\n", | ||
" },\n", | ||
" \"nbformat\": 4,\n", | ||
" \"nbformat_minor\": 5\n", | ||
"}\n" | ||
], | ||
"id": "ca26b3103b0e7ce7" | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
}, | ||
"colab": { | ||
"provenance": [] | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters