Spaces:
Runtime error
Runtime error
File size: 1,293 Bytes
e725ae2 2f468d8 e725ae2 569d938 55e2242 569d938 e725ae2 |
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 |
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"<s>[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) |