Instructions to use krisoei/timgpt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use krisoei/timgpt with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("krisoei/timgpt", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Download handler.py from krisoei/timgpt: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/krisoei/timgpt/resolve/main/handler.py
- Command line
-
hf download hf://krisoei/timgpt/handler.py
-
curl -L -o handler.py https://huggingface.co/krisoei/timgpt/resolve/main/handler.py
1.59 kB
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| import torch | |
| class EndpointHandler: | |
| def __init__(self, path="krisoei/timgpt"): | |
| if not path: | |
| raise ValueError("A valid model path or name must be provided.") | |
| # Load tokenizer and model | |
| self.tokenizer = AutoTokenizer.from_pretrained(path) | |
| self.model = AutoModelForCausalLM.from_pretrained( | |
| path, | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| # Set up text-generation pipeline | |
| self.pipe = pipeline( | |
| "text-generation", | |
| model=self.model, | |
| tokenizer=self.tokenizer, | |
| max_new_tokens=512, | |
| do_sample=True, | |
| temperature=0.7, | |
| top_p=0.95, | |
| ) | |
| def __call__(self, data): | |
| # Validate input data | |
| if not isinstance(data, dict): | |
| return {"error": "Input must be a JSON object."} | |
| prompt = data.get("inputs", "") | |
| if not prompt: | |
| return {"error": "No input provided."} | |
| try: | |
| # Generate response | |
| outputs = self.pipe(prompt) | |
| if outputs: | |
| response = outputs[0]['generated_text'] | |
| # Remove the original prompt from the response | |
| response = response[len(prompt):].strip() | |
| return {"generated_text": response} | |
| else: | |
| return {"error": "No output generated."} | |
| except Exception as e: | |
| return {"error": str(e)} | |