File size: 1,272 Bytes
7fa6da1 6c5ce87 626e0d7 7fa6da1 7fb7223 7fa6da1 7fb7223 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import time
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
torch.random.manual_seed(0)
model = AutoModelForCausalLM.from_pretrained(
"microsoft/Phi-3-mini-128k-instruct",
torch_dtype="auto",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct")
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
generation_args = {
"max_new_tokens": 500,
"return_full_text": False,
"temperature": 0.0,
"do_sample": False,
}
def chat(message, history):
messages = [
{"role": "user", "content": "Hi"},
{"role": "assistant", "content": "Hello.. How may I help you?"},
{"role": "user", "content": message},
]
output = pipe(messages, **generation_args)
print(output[0]['generated_text'])
return output[0]['generated_text']
description = """
<div style="text-align: center;">
<h1>Phi-3-mini-128k-instruct Chatbot</h1>
<p>This chatbot is based on the Phi-3-mini-128k-instruct model by Microsoft.</p>
<p>Feel free to ask any questions or start a conversation!</p>
</div>
"""
demo = gr.ChatInterface(chat, description=description).queue()
if __name__ == "__main__":
demo.launch()
|