ceaserbutdumb commited on
Commit
06a266b
·
1 Parent(s): d0da8d9
Files changed (2) hide show
  1. app.py +23 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from peft import PeftModel, PeftConfig
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import gradio as gr
4
+
5
+ config = PeftConfig.from_pretrained("pranjalpandey/gemma-open-instruct")
6
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b")
7
+ model = PeftModel.from_pretrained(model, "pranjalpandey/gemma-open-instruct")
8
+ # model = AutoPeftModelForCausalLM.from_pretrained("pranjalpandey/llama-7b-finetuned-dialogue-summarizer")
9
+ tokenizer = AutoTokenizer.from_pretrained("pranjalpandey/gemma-open-instruct")
10
+ model = model.to("cuda")
11
+
12
+ def response(prompt):
13
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
14
+ outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=100)
15
+ return tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0].split("# Response:")[1].strip()
16
+
17
+ ir = gr.Interface(
18
+ fn=response,
19
+ inputs=["text"],
20
+ outputs=["text"],
21
+ )
22
+
23
+ ir.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ peft
2
+ accelerate
3
+ transformers
4
+ gradio