Spaces:
Runtime error
Runtime error
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| import gradio as gr | |
| torch.random.manual_seed(0) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "microsoft/Phi-3-mini-128k-instruct", | |
| device_map="auto", | |
| torch_dtype="auto", | |
| trust_remote_code=True, | |
| low_cpu_mem_usage=True, | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct") | |
| messages = [ | |
| {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"}, | |
| {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."}, | |
| {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"}, | |
| ] | |
| pipe = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| ) | |
| generation_args = { | |
| "max_new_tokens": 256, | |
| "return_full_text": False, | |
| "temperature": 0.2, | |
| "do_sample": True, | |
| } | |
| def phi3_fun(message,chat_history): | |
| messages=[ | |
| {"role": "user", "content": message}, | |
| ] | |
| output = pipe(messages, **generation_args) | |
| respond = output[0]['generated_text'] | |
| return respond | |
| title = "Phi-3 " | |
| examples = [ | |
| 'How are You?', | |
| "talk about your self", | |
| ] | |
| gr.ChatInterface( | |
| fn=phi3_fun, | |
| title =title, | |
| examples = examples | |
| ).launch(debug=True) | |
| # demo = gr.Interface(fn=phi3_fun, inputs="text", outputs="text",title =title, | |
| # examples = examples) | |
| # demo.launch() | |
| # output = pipe(messages, **generation_args) | |
| # print(output[0]['generated_text']) | |