Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +69 -0
- requirements.txt +9 -0
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from peft import AutoPeftModelForCausalLM
|
2 |
+
from transformers import GenerationConfig
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
import torch
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
# model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
# "tiiuae/falcon-7b-instruct",
|
9 |
+
# torch_dtype=torch.bfloat16,
|
10 |
+
# trust_remote_code=True,
|
11 |
+
# device_map="auto",
|
12 |
+
# low_cpu_mem_usage=True,
|
13 |
+
# )
|
14 |
+
|
15 |
+
|
16 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
17 |
+
"Aneeth/zephyr_10k",
|
18 |
+
low_cpu_mem_usage=True,
|
19 |
+
return_dict=True,
|
20 |
+
torch_dtype=torch.float16,
|
21 |
+
device_map="auto",
|
22 |
+
trust_remote_code=True
|
23 |
+
)
|
24 |
+
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained("Aneeth/zephyr_10k")
|
26 |
+
generation_config = GenerationConfig(
|
27 |
+
do_sample=True,
|
28 |
+
top_k=1,
|
29 |
+
temperature=0.5,
|
30 |
+
max_new_tokens=5000,
|
31 |
+
pad_token_id=tokenizer.eos_token_id,
|
32 |
+
|
33 |
+
)
|
34 |
+
|
35 |
+
|
36 |
+
def process_data_sample(example):
|
37 |
+
|
38 |
+
processed_example = "<|system|>\n Generate an authentic job description using the given input.\n<|user|>\n" + example["instruction"] + "\n<|assistant|>\n"
|
39 |
+
|
40 |
+
return processed_example
|
41 |
+
|
42 |
+
def generate_text(prompt):
|
43 |
+
|
44 |
+
inp_str = process_data_sample(
|
45 |
+
{
|
46 |
+
"instruction": prompt,
|
47 |
+
}
|
48 |
+
)
|
49 |
+
inputs = tokenizer(inp_str, return_tensors="pt").to("cpu")
|
50 |
+
outputs = model.generate(**inputs, generation_config=generation_config)
|
51 |
+
response=tokenizer.decode(outputs[0], skip_special_tokens=True)
|
52 |
+
return response
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
def main():
|
58 |
+
st.title("Zephyr Inference")
|
59 |
+
# Get input from user
|
60 |
+
input_text = st.text_area("Input JD prompt", "Type here...")
|
61 |
+
|
62 |
+
# Generate text on button click
|
63 |
+
if st.button("Generate Text"):
|
64 |
+
generated_text = generate_text(input_text)
|
65 |
+
st.subheader("Generated Text:")
|
66 |
+
st.write(generated_text)
|
67 |
+
|
68 |
+
if __name__ == "__main__":
|
69 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
trl
|
3 |
+
peft
|
4 |
+
accelerate
|
5 |
+
bitsandbytes
|
6 |
+
auto-gptq
|
7 |
+
optimum
|
8 |
+
einops
|
9 |
+
safetensors
|