File size: 903 Bytes
e143d31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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=