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
Delete handler.py
Browse files- handler.py +0 -69
handler.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
# handler.py
|
| 2 |
-
import json
|
| 3 |
-
from typing import List, Dict, Any
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
|
| 6 |
-
# ---- LOAD MODEL ON STARTUP ----
|
| 7 |
-
pipe = pipeline(
|
| 8 |
-
"text-generation",
|
| 9 |
-
model="Ephraimmm/PIDGIN_gemma-3",
|
| 10 |
-
device_map="auto"
|
| 11 |
-
)
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# ---- UTIL: convert OpenAI-like body into prompt ----
|
| 15 |
-
def build_prompt(messages: List[Dict[str, str]]) -> str:
|
| 16 |
-
out = []
|
| 17 |
-
for m in messages:
|
| 18 |
-
role = m["role"]
|
| 19 |
-
content = m["content"]
|
| 20 |
-
if role == "system":
|
| 21 |
-
out.append(f"<<SYS>> {content}\n")
|
| 22 |
-
elif role == "user":
|
| 23 |
-
out.append(f"User: {content}")
|
| 24 |
-
elif role == "assistant":
|
| 25 |
-
out.append(f"Assistant: {content}")
|
| 26 |
-
out.append("Assistant:")
|
| 27 |
-
return "\n".join(out)
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
# ---- MAIN HANDLER ENTRYPOINT ----
|
| 31 |
-
def handle(event, context=None):
|
| 32 |
-
"""AWS/SageMaker/HF style single entry."""
|
| 33 |
-
if isinstance(event, str): # if raw body
|
| 34 |
-
event = json.loads(event)
|
| 35 |
-
|
| 36 |
-
# Expect OpenAI style body
|
| 37 |
-
messages = event["messages"]
|
| 38 |
-
max_tokens = event.get("max_tokens", 256)
|
| 39 |
-
temperature = event.get("temperature", 0.7)
|
| 40 |
-
top_p = event.get("top_p", 0.95)
|
| 41 |
-
|
| 42 |
-
prompt = build_prompt(messages)
|
| 43 |
-
|
| 44 |
-
out = pipe(
|
| 45 |
-
prompt,
|
| 46 |
-
max_new_tokens=max_tokens,
|
| 47 |
-
do_sample=True,
|
| 48 |
-
temperature=temperature,
|
| 49 |
-
top_p=top_p,
|
| 50 |
-
eos_token_id=pipe.tokenizer.eos_token_id,
|
| 51 |
-
)[0]["generated_text"]
|
| 52 |
-
|
| 53 |
-
# extract only the assistant continuation
|
| 54 |
-
completion = out.replace(prompt, "").strip()
|
| 55 |
-
|
| 56 |
-
# ---- RETURN IN OPENAI CHAT FORMAT ----
|
| 57 |
-
resp = {
|
| 58 |
-
"id": "chatcmpl-local-1",
|
| 59 |
-
"object": "chat.completion",
|
| 60 |
-
"choices": [{
|
| 61 |
-
"index": 0,
|
| 62 |
-
"finish_reason": "stop",
|
| 63 |
-
"message": {
|
| 64 |
-
"role": "assistant",
|
| 65 |
-
"content": completion
|
| 66 |
-
}
|
| 67 |
-
}],
|
| 68 |
-
}
|
| 69 |
-
return resp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|