Download app.py from fubrix/test1: direct link, hf CLI and curl.
- Browser
- Download file 897 Bytes
-
https://huggingface.co/spaces/fubrix/test1/resolve/main/app.py
- Command line
-
hf download hf://spaces/fubrix/test1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/fubrix/test1/resolve/main/app.py
897 Bytes
| from transformers import AutoProcessor, AutoModelForCausalLM | |
| MODEL_ID = "google/gemma-4-E2B-it" | |
| # Load model | |
| processor = AutoProcessor.from_pretrained(MODEL_ID) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL_ID, | |
| dtype="auto", | |
| device_map="auto" | |
| ) | |
| # Prompt | |
| messages = [ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": "Write a short joke about saving RAM."}, | |
| ] | |
| # Process input | |
| text = processor.apply_chat_template( | |
| messages, | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| enable_thinking=False | |
| ) | |
| inputs = processor(text=text, return_tensors="pt").to(model.device) | |
| input_len = inputs["input_ids"].shape[-1] | |
| # Generate output | |
| outputs = model.generate(**inputs, max_new_tokens=1024) | |
| response = processor.decode(outputs[0][input_len:], skip_special_tokens=False) | |
| # Parse output | |
| processor.parse_response(response) | |