omidk414 commited on
Commit
6cabfb0
·
verified ·
1 Parent(s): 05ddfbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -67
app.py CHANGED
@@ -1,70 +1,62 @@
1
  import gradio as gr
 
2
  import tensorflow as tf
3
- import numpy as np
4
- from pathlib import Path
5
-
6
- # Load your pre-trained model
7
- model = tf.keras.models.load_model('resume_generator_model.h5')
8
-
9
- # Path to the HTML template
10
- TEMPLATE_PATH = Path("templates/resume_template.html")
11
-
12
- def enhance_resume(resume_text, job_title):
13
- # Preprocess the inputs for the model
14
- input_text = resume_text + " Job Title: " + job_title
15
- input_data = np.array([input_text]) # Assuming a single input
16
- prediction = model.predict(input_data)
17
-
18
- # Assuming the model returns a dictionary-like structure
19
- enhanced_content = {
20
- "summary": prediction.get("summary", "No summary generated."),
21
- "technical_skills": prediction.get("technical_skills", "No technical skills generated."),
22
- "experience": prediction.get("experience", "No experience details generated."),
23
- "education": prediction.get("education", "No education details generated.")
24
- }
25
-
26
- return enhanced_content
27
-
28
- def fill_resume_template(resume_text, job_title):
29
- # Enhance the resume content using the model
30
- enhanced_content = enhance_resume(resume_text, job_title)
31
-
32
- # Read the HTML template
33
- with open(TEMPLATE_PATH, "r", encoding="utf-8") as file:
34
- template = file.read()
35
-
36
- # Replace placeholders with the enhanced content
37
- filled_resume = template.format(
38
- summary=enhanced_content["summary"],
39
- technical_skills=enhanced_content["technical_skills"],
40
- experience=enhanced_content["experience"],
41
- education=enhanced_content["education"]
42
- )
43
-
44
- return filled_resume
45
-
46
- # Gradio interface
47
- def gradio_interface(resume_text, job_title):
48
- # Generate the filled-in resume HTML
49
- filled_resume = fill_resume_template(resume_text, job_title)
50
 
51
- # Display the filled resume in the Gradio interface
52
- return filled_resume
53
-
54
- # Gradio UI components
55
- resume_input = gr.Textbox(label="Paste your Resume Text", placeholder="Paste your resume here...", lines=10)
56
- job_title_input = gr.Textbox(label="Job Title", placeholder="Enter the job title for enhancement...")
57
- output_html = gr.HTML(label="Enhanced Resume Output")
58
-
59
- # Gradio interface layout
60
- gradio_app = gr.Interface(
61
- fn=gradio_interface,
62
- inputs=[resume_input, job_title_input],
63
- outputs=output_html,
64
- title="AI Resume Enhancer",
65
- description="Upload your resume text and specify a job title to generate an optimized version.",
66
- theme="compact"
67
- )
68
-
69
- # Launch the Gradio app
70
- gradio_app.launch()
 
 
 
1
  import gradio as gr
2
+ import pandas as pd
3
  import tensorflow as tf
4
+ from huggingface_hub import InferenceClient
5
+ import fitz # PyMuPDF
6
+
7
+ # Load your TensorFlow model
8
+ model_path = 'resume_generator_model.h5'
9
+ resume_model = tf.keras.models.load_model(model_path)
10
+
11
+ # Initialize the LLaMA model
12
+ llama_client = InferenceClient("meta-llama/Meta-Llama-3.1-8B-Instruct")
13
+
14
+ # Function to extract text from PDF or text files
15
+ def extract_text(file):
16
+ text = ""
17
+ if file.name.endswith('.pdf'):
18
+ with fitz.open(file.name) as pdf:
19
+ for page in pdf:
20
+ text += page.get_text()
21
+ else:
22
+ text = file.read().decode('utf-8')
23
+ return text
24
+
25
+ # Function to enhance the resume using both models
26
+ def enhance_resume(file, job_title):
27
+ # Extract text from the uploaded resume
28
+ resume_text = extract_text(file)
29
+
30
+ # Generate enhancements using your model
31
+ # This is a placeholder for your actual model's prediction logic
32
+ enhanced_content = resume_model.predict([resume_text]) # Adjust as needed
33
+
34
+ # Use LLaMA to enhance the resume based on job title
35
+ llama_input = f"Enhance this resume for the job title: {job_title}. Original resume: {resume_text}"
36
+ llama_output = llama_client(llama_input)
37
+
38
+ # Combine outputs
39
+ final_output = f"{enhanced_content}\n\n{llama_output['generated_text']}"
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ # Load and fill in the HTML template
42
+ with open("templates/resume_template.html", "r") as f:
43
+ template = f.read()
44
+
45
+ # Replace placeholder with the user's name (extract name from resume)
46
+ user_name = "User" # Replace this with logic to extract the name from resume
47
+ filled_template = template.replace("{{ name }}", user_name)
48
+ filled_template = filled_template.replace("{{ content }}", final_output)
49
+
50
+ return filled_template
51
+
52
+ # Gradio Interface
53
+ gr.Interface(
54
+ fn=enhance_resume,
55
+ inputs=[
56
+ gr.File(label="Upload Resume (PDF/Text)"),
57
+ gr.Textbox(label="Job Title")
58
+ ],
59
+ outputs=gr.HTML(label="Enhanced Resume"),
60
+ title="Resume Enhancer",
61
+ description="Upload your resume and provide a job title to enhance your resume."
62
+ ).launch()