Any-to-Any
Transformers
English
Polish
transformer
hardbanai, hardbanrecords, audio-generation, text-generation, image-generation, ai-publishing, creative-ai, emotional-style, multimodal, polish-language, musicgen
Instructions to use HardbanRecordsLab/HardbanAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HardbanRecordsLab/HardbanAI with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("HardbanRecordsLab/HardbanAI", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from HardbanRecordsLab/HardbanAI: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/HardbanRecordsLab/HardbanAI/resolve/main/handler.py
- Command line
-
hf download hf://HardbanRecordsLab/HardbanAI/handler.py
-
curl -L -o handler.py https://huggingface.co/HardbanRecordsLab/HardbanAI/resolve/main/handler.py
1.15 kB
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| import torch | |
| import json | |
| # Inicjalizacja modelu i tokenizera (ładuj tylko raz, przy starcie handlera) | |
| model_path = "./" # ścieżka do folderu z modelem | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_path) | |
| model.eval() | |
| def handle(event, context): | |
| """ | |
| event: dict, z kluczem 'text' zawierającym tekst do przetworzenia | |
| context: obiekt kontekstowy (zależny od platformy, nieużywany tu) | |
| Zwraca dict z wygenerowanym tekstem. | |
| """ | |
| # Wczytaj input | |
| try: | |
| if isinstance(event, str): | |
| event = json.loads(event) | |
| text = event.get("text", "") | |
| except Exception as e: | |
| return {"error": f"Błąd parsowania danych wejściowych: {str(e)}"} | |
| if not text: | |
| return {"error": "Brak tekstu do przetworzenia."} | |
| # Tokenizacja i generacja | |
| inputs = tokenizer(text, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model.generate(**inputs) | |
| result = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return {"generated_text": result} | |