burberg92 commited on
Commit
c562ad0
1 Parent(s): c83d5b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from peft import PeftModel, PeftConfig
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ peft_model_id = "burberg92/resume_summary"
6
+ config = PeftConfig.from_pretrained(peft_model_id)
7
+ base_model = AutoModelForCausalLM.from_pretrained(
8
+ config.base_model_name_or_path,
9
+ return_dict=True,
10
+ load_in_8bit=False,
11
+ device_map="auto",
12
+ )
13
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
14
+
15
+ # Load the Lora model
16
+ model = PeftModel.from_pretrained(base_model, peft_model_id)
17
+
18
+ def make_inference(question):
19
+ input_text = "### Enter your Resume {}\n".format(question)
20
+ batch = tokenizer(input_text, return_tensors='pt')
21
+
22
+ with torch.cuda.amp.autocast():
23
+ output_tokens = model.generate(**batch, max_length=50, num_return_sequences=1)
24
+
25
+ return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
26
+
27
+ if __name__ == "__main__":
28
+ import gradio as gr
29
+
30
+ gr.Interface(
31
+ make_inference,
32
+ gr.inputs.Textbox(lines=2, label="Question"),
33
+ gr.outputs.Textbox(label="Answer"),
34
+ title="Exective Summary Generator",
35
+ description="Generated Executive Summary",
36
+ ).launch()