omidk414 commited on
Commit
f656a5a
·
verified ·
1 Parent(s): 31291e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -35
app.py CHANGED
@@ -1,53 +1,60 @@
 
1
  import gradio as gr
2
- import numpy as np
3
  import tensorflow as tf
4
  import spacy
5
- from huggingface_hub import InferenceClient
 
6
 
7
- # Load the LLaMA model
8
- llama_model = InferenceClient("meta-llama/Meta-Llama-3.1-8B-Instruct",
9
- token='YOUR_HUGGING_FACE_API_KEY')
10
 
11
  # Load your TensorFlow model
12
  model = tf.keras.models.load_model("resume_generator_model.h5")
13
 
14
- # Load spaCy model for NLP processing
15
- nlp = spacy.load("en_core_web_sm")
16
 
17
- def enhance_resume(uploaded_resume, job_title):
18
- # Step 1: Extract text from the uploaded resume
19
- resume_text = uploaded_resume.read().decode("utf-8")
20
 
21
- # Step 2: Process the resume text with spaCy
 
 
22
  doc = nlp(resume_text)
 
23
 
24
- # Extract entities or specific features you need for enhancement
25
- skills = [ent.text for ent in doc.ents if ent.label_ == "SKILL"]
26
- education = [ent.text for ent in doc.ents if ent.label_ == "EDUCATION"]
27
-
28
- # Step 3: Generate enhancement suggestions using your TensorFlow model
29
- # Assuming your model takes in the skills and job title and outputs enhancements
30
- # Here, you'll need to define the actual input shape your model expects
31
- # This is a simplified example:
32
- resume_features = np.array([skills, job_title])
33
- enhancements = model.predict(resume_features)
34
-
35
- # Step 4: Generate enhancements using LLaMA
36
- llama_response = llama_model("Suggest enhancements for a resume for the job title: {}".format(job_title))
37
-
38
- # Step 5: Combine outputs
39
- enhanced_resume = f"Original Resume:\n{resume_text}\n\nEnhancements:\n{enhancements}\n\nLLaMA Suggestions:\n{llama_response}"
40
-
41
- return enhanced_resume
42
-
43
- # Gradio interface
 
 
 
 
 
44
  iface = gr.Interface(
45
  fn=enhance_resume,
46
- inputs=[gr.inputs.File(label="Upload your resume (txt or pdf)"),
47
- gr.inputs.Textbox(label="Job Title")],
48
- outputs=gr.outputs.Textbox(label="Enhanced Resume"),
49
  title="Resume Enhancer",
50
- description="Upload your resume and specify the job title to get an enhanced version."
51
  )
52
 
 
53
  iface.launch()
 
1
+ import os
2
  import gradio as gr
 
3
  import tensorflow as tf
4
  import spacy
5
+ from transformers import InferenceClient
6
+ from jinja2 import Environment, FileSystemLoader
7
 
8
+ # Load spaCy model
9
+ nlp = spacy.load("en_core_web_sm")
 
10
 
11
  # Load your TensorFlow model
12
  model = tf.keras.models.load_model("resume_generator_model.h5")
13
 
14
+ # Initialize the InferenceClient for LLaMA
15
+ llama_client = InferenceClient(model="meta-llama/Meta-Llama-3.1-8B-Instruct")
16
 
17
+ # Configure Jinja2 for template rendering
18
+ env = Environment(loader=FileSystemLoader("templates"))
 
19
 
20
+ # Helper function to enhance the resume content using spaCy and LLaMA
21
+ def enhance_resume(resume_text, job_title):
22
+ # 1. Analyze the resume using spaCy
23
  doc = nlp(resume_text)
24
+ entities = [(ent.text, ent.label_) for ent in doc.ents]
25
 
26
+ # 2. Use LLaMA model to generate new content based on the job title
27
+ prompt = f"Enhance the following resume text for a {job_title} position: {resume_text}"
28
+ llama_response = llama_client(prompt)
29
+
30
+ # 3. Use your custom model for additional predictions (e.g., key skills, professional summary)
31
+ # Here, we simulate predictions based on your model's capabilities
32
+ predictions = model.predict([[job_title]]) # Adjust this based on your model's input requirements
33
+ enhanced_skills = ["Skill A", "Skill B", "Skill C"] # Replace with model-predicted skills
34
+
35
+ # 4. Populate the HTML template with the enhanced content
36
+ template = env.get_template("resume_template.html")
37
+ rendered_resume = template.render(
38
+ name="John Doe",
39
+ email="john.doe@example.com",
40
+ phone="123-456-7890",
41
+ location="San Francisco, CA",
42
+ summary=llama_response["generated_text"],
43
+ skills=enhanced_skills,
44
+ experiences=["Experience 1", "Experience 2"],
45
+ educations=["Bachelor's in Computer Science", "Master's in Data Science"]
46
+ )
47
+
48
+ return rendered_resume
49
+
50
+ # Define the Gradio interface
51
  iface = gr.Interface(
52
  fn=enhance_resume,
53
+ inputs=["text", "text"], # Upload resume text and specify job title
54
+ outputs="html", # Rendered HTML output
 
55
  title="Resume Enhancer",
56
+ description="Upload a resume and specify a job title to enhance it.",
57
  )
58
 
59
+ # Launch the Gradio app
60
  iface.launch()