Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from peft import AutoPeftModelForCausalLM
|
3 |
+
from transformers import AutoTokenizer, GPTQConfig, GenerationConfig
|
4 |
+
|
5 |
+
gptq_config = GPTQConfig(bits=4, disable_exllama=True)
|
6 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
7 |
+
"Aneeth/zephyr_10k",
|
8 |
+
return_dict=True,
|
9 |
+
torch_dtype=torch.float32,
|
10 |
+
trust_remote_code=True,
|
11 |
+
quantization_config=gptq_config
|
12 |
+
)
|
13 |
+
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("Aneeth/zephyr_10k")
|
15 |
+
generation_config = GenerationConfig(
|
16 |
+
do_sample=True,
|
17 |
+
top_k=1,
|
18 |
+
temperature=0.5,
|
19 |
+
max_new_tokens=5000,
|
20 |
+
pad_token_id=tokenizer.eos_token_id,
|
21 |
+
)
|
22 |
+
|
23 |
+
def process_data_sample(example):
|
24 |
+
processed_example = "\n Generate an authentic job description using the given input.\n\n" + example["instruction"] + "\n\n"
|
25 |
+
return processed_example
|
26 |
+
|
27 |
+
def generate_text(prompt):
|
28 |
+
inp_str = process_data_sample({"instruction": prompt})
|
29 |
+
inputs = tokenizer(inp_str, return_tensors="pt").to("cpu")
|
30 |
+
outputs = model.generate(**inputs, generation_config=generation_config)
|
31 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
32 |
+
return response
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", live=True)
|
35 |
+
iface.launch()
|