Spaces:
Runtime error
Runtime error
Download app.py from TestFZAI/Modal_Usage: direct link, hf CLI and curl.
- Browser
- Download file 721 Bytes
-
https://huggingface.co/spaces/TestFZAI/Modal_Usage/resolve/main/app.py
- Command line
-
hf download hf://spaces/TestFZAI/Modal_Usage/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TestFZAI/Modal_Usage/resolve/main/app.py
721 Bytes
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct" | |
| # Load tokenizer and model | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL_NAME, | |
| device_map="auto", # puts model on GPU if available | |
| torch_dtype="auto" # chooses best precision | |
| ) | |
| # Create text-generation pipeline | |
| pipe = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer | |
| ) | |
| # Prompt for testing | |
| prompt = "Explain the concept of cricket in simple terms." | |
| # Generate response | |
| output = pipe(prompt, max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.9) | |
| print(output[0]["generated_text"]) | |