Instructions to use ChrisCleaner/influence_upload_test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use ChrisCleaner/influence_upload_test with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy) # See https://github.com/keras-team/tf-keras for more details. from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("ChrisCleaner/influence_upload_test") - Notebooks
- Google Colab
- Kaggle
| # import tensorflow as tf | |
| # from google.protobuf.struct_pb2 import Struct | |
| # import struct2tensor.ops.gen_decode_proto_sparse | |
| # def create_proto_message(text): | |
| # message = Struct() | |
| # message.fields["task_data"].string_value = text | |
| # return message.SerializeToString() | |
| # class TFProtoModel: | |
| # def __init__(self, model_path): | |
| # self.model = tf.saved_model.load(model_path) | |
| # self.infer = self.model.signatures['serving_default'] | |
| # def predict(self, text): | |
| # proto_data = create_proto_message(text) | |
| # input_tensor = tf.constant([proto_data], dtype=tf.string) | |
| # result = self.infer(inputs=input_tensor) | |
| # return result['outputs'].numpy() | |
| # # Initialize model when the file is loaded | |
| # model = TFProtoModel("model") | |
| # # This is the function Hugging Face will call | |
| # def pipeline(text): | |
| # return model.predict(text) | |
| import tensorflow as tf | |
| from google.protobuf.struct_pb2 import Struct | |
| from transformers import Pipeline | |
| import struct2tensor.ops.gen_decode_proto_sparse | |
| def create_proto_message(text): | |
| message = Struct() | |
| message.fields["task_data"].string_value = text | |
| return message.SerializeToString() | |
| class TFProtoModel(Pipeline): | |
| def __init__(self, model_path="model"): | |
| self.model = tf.saved_model.load(model_path) | |
| self.infer = self.model.signatures['serving_default'] | |
| def _sanitize_parameters(self, **kwargs): | |
| return {}, {}, {} | |
| def preprocess(self, text): | |
| proto_data = create_proto_message(text) | |
| return tf.constant([proto_data], dtype=tf.string) | |
| def _forward(self, input_tensor): | |
| result = self.infer(inputs=input_tensor) | |
| return result['outputs'].numpy() | |
| def postprocess(self, model_outputs): | |
| return {"score": float(model_outputs[0])} | |
| pipeline = TFProtoModel | |
| # To specify the task | |
| task = "text-classification" # or another appropriate task type |