Spaces:
Sleeping
Sleeping
token
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import os
|
2 |
import torch
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
4 |
import gradio as gr
|
@@ -21,19 +21,29 @@ huggingface_token = os.getenv('HUGGINGFACE_TOKEN')
|
|
21 |
if not huggingface_token:
|
22 |
raise Exception("Hugging Face token not found. Please set it as an environment variable 'HUGGINGFACE_TOKEN'.")
|
23 |
|
|
|
|
|
|
|
24 |
# Load the base model with the updated quantization configuration
|
25 |
base_model = AutoModelForCausalLM.from_pretrained(
|
26 |
base_model_id,
|
27 |
quantization_config=quantization_config,
|
28 |
trust_remote_code=True,
|
29 |
-
token=huggingface_token # Use the token parameter
|
30 |
-
|
|
|
31 |
|
32 |
# Load the tokenizer
|
33 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Load the fine-tuned model
|
36 |
-
ft_model = PeftModel.from_pretrained(base_model, "checkpoint-2800")
|
37 |
|
38 |
def formatting_func(job_description):
|
39 |
text = f"### The job description: {job_description}\n ### The skills: "
|
@@ -65,4 +75,4 @@ inputs = gr.Textbox(lines=10, label="Job description:", placeholder="Enter or pa
|
|
65 |
outputs = gr.Textbox(label="Required skills:", placeholder="The required skills will be displayed here...")
|
66 |
|
67 |
gr.Interface(fn=generate_skills, inputs=inputs, outputs=outputs, title="Job Skills Analysis",
|
68 |
-
description="Paste the job description in the text box below and the model will show the required skills for candidates.").launch()
|
|
|
1 |
+
import os # Ensure os is imported
|
2 |
import torch
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
4 |
import gradio as gr
|
|
|
21 |
if not huggingface_token:
|
22 |
raise Exception("Hugging Face token not found. Please set it as an environment variable 'HUGGINGFACE_TOKEN'.")
|
23 |
|
24 |
+
# Define cache directory
|
25 |
+
cache_dir = "./cache"
|
26 |
+
|
27 |
# Load the base model with the updated quantization configuration
|
28 |
base_model = AutoModelForCausalLM.from_pretrained(
|
29 |
base_model_id,
|
30 |
quantization_config=quantization_config,
|
31 |
trust_remote_code=True,
|
32 |
+
token=huggingface_token, # Use the token parameter
|
33 |
+
cache_dir=cache_dir # Specify cache directory
|
34 |
+
).to("cuda") # Move model to CUDA
|
35 |
|
36 |
# Load the tokenizer
|
37 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
38 |
+
base_model_id,
|
39 |
+
add_bos_token=True,
|
40 |
+
trust_remote_code=True,
|
41 |
+
token=huggingface_token,
|
42 |
+
cache_dir=cache_dir # Specify cache directory
|
43 |
+
)
|
44 |
|
45 |
# Load the fine-tuned model
|
46 |
+
ft_model = PeftModel.from_pretrained(base_model, "checkpoint-2800", cache_dir=cache_dir).to("cuda") # Move model to CUDA
|
47 |
|
48 |
def formatting_func(job_description):
|
49 |
text = f"### The job description: {job_description}\n ### The skills: "
|
|
|
75 |
outputs = gr.Textbox(label="Required skills:", placeholder="The required skills will be displayed here...")
|
76 |
|
77 |
gr.Interface(fn=generate_skills, inputs=inputs, outputs=outputs, title="Job Skills Analysis",
|
78 |
+
description="Paste the job description in the text box below and the model will show the required skills for candidates.").launch(share=True) # Set share=True to create a public link
|