Instructions to use AnalyticsIntelligence/PIDGIN_gemma3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AnalyticsIntelligence/PIDGIN_gemma3 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AnalyticsIntelligence/PIDGIN_gemma3", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Download handler.py from AnalyticsIntelligence/PIDGIN_gemma3: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/AnalyticsIntelligence/PIDGIN_gemma3/resolve/91c1aad4804affcfe6e839cf3cd93df4fb863d78/handler.py
- Command line
-
hf download hf://AnalyticsIntelligence/PIDGIN_gemma3@91c1aad4804affcfe6e839cf3cd93df4fb863d78/handler.py
-
curl -L -o handler.py https://huggingface.co/AnalyticsIntelligence/PIDGIN_gemma3/resolve/91c1aad4804affcfe6e839cf3cd93df4fb863d78/handler.py
1.83 kB
| # handler.py | |
| import json | |
| from typing import List, Dict, Any | |
| from transformers import pipeline | |
| # ---- LOAD MODEL ON STARTUP ---- | |
| pipe = pipeline( | |
| "text-generation", | |
| model="Ephraimmm/PIDGIN_gemma-3", | |
| device_map="auto" | |
| ) | |
| # ---- UTIL: convert OpenAI-like body into prompt ---- | |
| def build_prompt(messages: List[Dict[str, str]]) -> str: | |
| out = [] | |
| for m in messages: | |
| role = m["role"] | |
| content = m["content"] | |
| if role == "system": | |
| out.append(f"<<SYS>> {content}\n") | |
| elif role == "user": | |
| out.append(f"User: {content}") | |
| elif role == "assistant": | |
| out.append(f"Assistant: {content}") | |
| out.append("Assistant:") | |
| return "\n".join(out) | |
| # ---- MAIN HANDLER ENTRYPOINT ---- | |
| def handle(event, context=None): | |
| """AWS/SageMaker/HF style single entry.""" | |
| if isinstance(event, str): # if raw body | |
| event = json.loads(event) | |
| # Expect OpenAI style body | |
| messages = event["messages"] | |
| max_tokens = event.get("max_tokens", 256) | |
| temperature = event.get("temperature", 0.7) | |
| top_p = event.get("top_p", 0.95) | |
| prompt = build_prompt(messages) | |
| out = pipe( | |
| prompt, | |
| max_new_tokens=max_tokens, | |
| do_sample=True, | |
| temperature=temperature, | |
| top_p=top_p, | |
| eos_token_id=pipe.tokenizer.eos_token_id, | |
| )[0]["generated_text"] | |
| # extract only the assistant continuation | |
| completion = out.replace(prompt, "").strip() | |
| # ---- RETURN IN OPENAI CHAT FORMAT ---- | |
| resp = { | |
| "id": "chatcmpl-local-1", | |
| "object": "chat.completion", | |
| "choices": [{ | |
| "index": 0, | |
| "finish_reason": "stop", | |
| "message": { | |
| "role": "assistant", | |
| "content": completion | |
| } | |
| }], | |
| } | |
| return resp | |