Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,10 +14,10 @@ login(huggingface_token)
|
|
14 |
# model_name = "meta-llama/Llama-3.2-3B-Instruct"
|
15 |
model_name = "meta-llama/Llama-3.2-1B-Instruct"
|
16 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
17 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
18 |
|
19 |
#pipe = pipeline(model=model, tokenizer=tokenizer, max_length = 512) # Check documentation without "feature-extraction"
|
20 |
-
pipe = pipeline(task = 'text-generation', model=model, tokenizer=tokenizer, max_length = 512) # Check documentation without "feature-extraction"
|
21 |
|
22 |
|
23 |
# Use transformers pipeline
|
@@ -35,47 +35,38 @@ uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
|
35 |
print("Query: ", query)
|
36 |
|
37 |
if uploaded_file is not None:
|
38 |
-
# Read CSV file
|
39 |
df = pd.read_csv(uploaded_file)
|
40 |
|
41 |
-
job_title
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
#
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
# Example
|
76 |
-
if query:
|
77 |
-
try:
|
78 |
-
valid_query = ConsultModel(query=query)
|
79 |
-
st.success("Valid consult.")
|
80 |
-
except ValueError as e:
|
81 |
-
st.error(f"Validation error: {e}")
|
|
|
14 |
# model_name = "meta-llama/Llama-3.2-3B-Instruct"
|
15 |
model_name = "meta-llama/Llama-3.2-1B-Instruct"
|
16 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, device_map = 'auto')
|
18 |
|
19 |
#pipe = pipeline(model=model, tokenizer=tokenizer, max_length = 512) # Check documentation without "feature-extraction"
|
20 |
+
pipe = pipeline(task = 'text-generation', model=model, tokenizer=tokenizer, max_length = 512, device = 'auto') # Check documentation without "feature-extraction"
|
21 |
|
22 |
|
23 |
# Use transformers pipeline
|
|
|
35 |
print("Query: ", query)
|
36 |
|
37 |
if uploaded_file is not None:
|
|
|
38 |
df = pd.read_csv(uploaded_file)
|
39 |
|
40 |
+
if 'job_title' not in df.columns:
|
41 |
+
st.error("The uploaded CSV must contain a 'job_title' column.")
|
42 |
+
else:
|
43 |
+
job_titles = df['job_title'].tolist()
|
44 |
+
|
45 |
+
if query:
|
46 |
+
st.write("Query:", query)
|
47 |
+
|
48 |
+
# Crear el prompt para el LLM
|
49 |
+
prompt = f"""
|
50 |
+
You are an AI assistant. You will be given a list of job titles and a search query.
|
51 |
+
Your task is to calculate the cosine similarity score between the query and each job title.
|
52 |
+
You should then return a sorted list of job titles based on the similarity score, from highest to lowest.
|
53 |
+
Provide the output in the following format:
|
54 |
+
|
55 |
+
1. Job Title: [Job Title], Score: [Cosine Similarity Score]
|
56 |
+
2. Job Title: [Job Title], Score: [Cosine Similarity Score]
|
57 |
+
...
|
58 |
+
|
59 |
+
Query: {query}
|
60 |
+
Job Titles: {job_titles}
|
61 |
+
"""
|
62 |
+
|
63 |
+
# Llamar al modelo con el prompt
|
64 |
+
try:
|
65 |
+
response = pipe(prompt, max_length=1024, num_return_sequences=1)
|
66 |
+
|
67 |
+
# Mostrar la respuesta del modelo
|
68 |
+
st.write("Model Answer:")
|
69 |
+
st.write(response[0]['generated_text'])
|
70 |
+
|
71 |
+
except Exception as e:
|
72 |
+
st.error(f"Error while processing: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|