HimankJ's picture
Update app.py
da38199 verified
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
import gradio as gr
import torch
model = AutoModelForCausalLM.from_pretrained(
"microsoft/Phi-3.5-mini-instruct",
torch_dtype=torch.bfloat16,
trust_remote_code=True
)
model.load_adapter('./phi3_custom_oasst1_v1')
tokenizer = AutoTokenizer.from_pretrained('./phi3_custom_oasst1_v1', trust_remote_code=True)
def generateText(inputText, num_tokens=200):
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=num_tokens)
result = pipe(f'''{inputText}''')
return result[0]['generated_text']
title = "Fine tuned Phi3.5 instruct model on OpenAssist dataset using QLora"
description = '''
Phi-3.5-mini is a lightweight, state-of-the-art open model built upon datasets used for Phi-3 - synthetic data and filtered publicly available websites - with a focus on very high-quality, reasoning dense data.
The model belongs to the Phi-3 model family and supports 128K token context length.
The model underwent a rigorous enhancement process, incorporating both supervised fine-tuning, proximal policy optimization, and direct preference optimization to ensure precise instruction adherence and robust safety measures.
This demo utilises a fine tuned version of Phi3.5 instruct model using QLora on OpenAssist dataset - a human-generated, human-annotated assistant-style conversation corpus consisting of 161,443 messages in 35 different languages, annotated with 461,292 quality ratings, resulting in over 10,000 fully annotated conversation trees.
'''
examples = [
["How do I build a PC?", 200],
["write me a top 10 list of the funniest ways to die?", 300],
["Write a response that disagrees with the following post: 'Technology is everything that doesn't work yet.'?", 300]
]
demo = gr.Interface(
generateText,
inputs = [
gr.Textbox(label="User Question"),
gr.Slider(100, 500, value = 200, step=100, label="Number of Output tokens"),
],
outputs = [
gr.Text(),
],
title = title,
description = description,
examples = examples
)
demo.launch()