import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline import torch from peft import LoraConfig, PeftModel base_model_name = "microsoft/phi-2" new_model = "./checkpoint_360" model = AutoModelForCausalLM.from_pretrained( "microsoft/phi-2", trust_remote_code=True) model.config.use_cache = False model.load_adapter(new_model) tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True) tokenizer.pad_token = tokenizer.eos_token tokenizer.padding_side = "right" def QLoRA_Chatgpt(prompt): print(prompt) pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200) result = pipe(f"[INST] {prompt} [/INST]") return(result[0]['generated_text']) # return "Hello " + name + "!!" # Define Interface description = 'An AI assistant that works on the Microsoft Phi 2 model, which has been finetuned on the Open Assistant dataset using the QLora method, operates effectively. ' title = 'AI Chat bot finetuned on Microsoft Phi 2 model using QLORA' iface = gr.Interface(fn=QLoRA_Chatgpt, inputs=gr.Textbox("how can help you today", label='prompt'), outputs=gr.Textbox(label='Generated-output',scale = 2), title = title, description = description) iface.launch(share=True)