JamieAi33's picture
Add PEFT model hosting app
e143d31
raw
history blame
903 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the PEFT model and tokenizer from Hugging Face Hub
model_name = "JamieAi33/Phi-2_PEFT"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define the prediction function
def generate_text(prompt, max_length=100):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=max_length)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# PEFT LLM Demo")
gr.Markdown("Generate text using the Phi-2 PEFT model.")
with gr.Row():
prompt_input = gr.Textbox(label="Input Prompt", placeholder="Enter a prompt here...")
max_tokens_input = gr.Slider(label="Max Tokens", minimum=10, maximum=200, value=