Spaces:
Runtime error

Modal_Usage / app.py
TestFZAI's picture
Update app.py
370708c verified
Raw History Blame Contribute Delete
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"])