JamieAi33 commited on
Commit
e143d31
·
1 Parent(s): 6f2cdb1

Add PEFT model hosting app

Browse files
Files changed (2) hide show
  1. app.py +21 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load the PEFT model and tokenizer from Hugging Face Hub
5
+ model_name = "JamieAi33/Phi-2_PEFT"
6
+ model = AutoModelForCausalLM.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # Define the prediction function
10
+ def generate_text(prompt, max_length=100):
11
+ inputs = tokenizer(prompt, return_tensors="pt")
12
+ outputs = model.generate(**inputs, max_new_tokens=max_length)
13
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+
15
+ # Create the Gradio interface
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("# PEFT LLM Demo")
18
+ gr.Markdown("Generate text using the Phi-2 PEFT model.")
19
+ with gr.Row():
20
+ prompt_input = gr.Textbox(label="Input Prompt", placeholder="Enter a prompt here...")
21
+ max_tokens_input = gr.Slider(label="Max Tokens", minimum=10, maximum=200, value=
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ transformers