| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| import torch | |
| import gradio as gr | |
| model_id = "microsoft/phi-2" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32) | |
| pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| def chat(prompt): | |
| result = pipe(prompt, max_new_tokens=100, temperature=0.7) | |
| return result[0]["generated_text"] | |
| iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Phi-2 NPC Chat") | |
| iface.launch() | |