Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
import os
|
2 |
from cerebras.cloud.sdk import Cerebras
|
3 |
-
from
|
4 |
from weasyprint import HTML
|
5 |
import gradio as gr
|
6 |
|
7 |
# Ensure you get the API key from environment variables
|
8 |
api_key = os.environ.get("CEREBRAS_API_KEY")
|
9 |
|
|
|
|
|
|
|
10 |
# Functions for resume optimization
|
11 |
def create_prompt(resume_string: str, jd_string: str) -> str:
|
12 |
"""
|
@@ -88,26 +91,30 @@ def get_resume_response(prompt: str, api_key: str, model: str = "llama-3.3-70b",
|
|
88 |
|
89 |
return response_string
|
90 |
|
91 |
-
def process_resume(
|
92 |
"""
|
93 |
Process a resume file against a job description to create an optimized version.
|
94 |
"""
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
-
|
100 |
-
|
|
|
101 |
|
102 |
-
|
103 |
-
response_string = get_resume_response(prompt, api_key)
|
104 |
-
response_list = response_string.split("## Additional Suggestions")
|
105 |
-
|
106 |
-
# Extract new resume and suggestions for improvement
|
107 |
-
new_resume = response_list[0]
|
108 |
-
suggestions = "## Additional Suggestions \n\n" + response_list[1]
|
109 |
|
110 |
-
|
|
|
111 |
|
112 |
def export_resume(new_resume):
|
113 |
"""
|
@@ -116,10 +123,10 @@ def export_resume(new_resume):
|
|
116 |
try:
|
117 |
# Save as PDF
|
118 |
output_pdf_file = "resumes/resume_new.pdf"
|
119 |
-
|
120 |
# Convert Markdown to HTML
|
121 |
-
html_content =
|
122 |
-
|
123 |
# Convert HTML to PDF and save
|
124 |
HTML(string=html_content).write_pdf(output_pdf_file, stylesheets=['resumes/style.css'])
|
125 |
|
@@ -135,7 +142,7 @@ with gr.Blocks() as app:
|
|
135 |
|
136 |
# Gather inputs
|
137 |
with gr.Row():
|
138 |
-
resume_input = gr.File(label="Upload Your Resume (
|
139 |
jd_input = gr.Textbox(label="Paste the Job Description Here", lines=9, interactive=True, placeholder="Paste job description...")
|
140 |
|
141 |
run_button = gr.Button("Optimize Resume π€")
|
@@ -148,7 +155,7 @@ with gr.Blocks() as app:
|
|
148 |
output_resume = gr.Textbox(label="Edit resume and export!", interactive=True)
|
149 |
export_button = gr.Button("Export Resume as PDF π")
|
150 |
export_result = gr.Markdown(label="Export Result")
|
151 |
-
|
152 |
# Event binding
|
153 |
run_button.click(process_resume, inputs=[resume_input, jd_input], outputs=[output_resume_md, output_resume, output_suggestions])
|
154 |
export_button.click(export_resume, inputs=[output_resume], outputs=[export_result])
|
|
|
1 |
import os
|
2 |
from cerebras.cloud.sdk import Cerebras
|
3 |
+
from markitdown import MarkItDown
|
4 |
from weasyprint import HTML
|
5 |
import gradio as gr
|
6 |
|
7 |
# Ensure you get the API key from environment variables
|
8 |
api_key = os.environ.get("CEREBRAS_API_KEY")
|
9 |
|
10 |
+
# Initialize MarkItDown instance
|
11 |
+
md_converter = MarkItDown()
|
12 |
+
|
13 |
# Functions for resume optimization
|
14 |
def create_prompt(resume_string: str, jd_string: str) -> str:
|
15 |
"""
|
|
|
91 |
|
92 |
return response_string
|
93 |
|
94 |
+
def process_resume(resume_file, jd_string):
|
95 |
"""
|
96 |
Process a resume file against a job description to create an optimized version.
|
97 |
"""
|
98 |
+
try:
|
99 |
+
# Convert the uploaded file to Markdown
|
100 |
+
result = md_converter.convert(resume_file.name)
|
101 |
+
resume_string = result.text_content
|
102 |
+
|
103 |
+
# Create prompt for optimization
|
104 |
+
prompt = create_prompt(resume_string, jd_string)
|
105 |
+
|
106 |
+
# Generate the optimized resume using Cerebras' Llama 3.3 70B model
|
107 |
+
response_string = get_resume_response(prompt, api_key)
|
108 |
+
response_list = response_string.split("## Additional Suggestions")
|
109 |
|
110 |
+
# Extract new resume and suggestions for improvement
|
111 |
+
new_resume = response_list[0]
|
112 |
+
suggestions = "## Additional Suggestions \n\n" + response_list[1]
|
113 |
|
114 |
+
return new_resume, new_resume, suggestions
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
+
except Exception as e:
|
117 |
+
return f"Error processing file: {str(e)}", "", ""
|
118 |
|
119 |
def export_resume(new_resume):
|
120 |
"""
|
|
|
123 |
try:
|
124 |
# Save as PDF
|
125 |
output_pdf_file = "resumes/resume_new.pdf"
|
126 |
+
|
127 |
# Convert Markdown to HTML
|
128 |
+
html_content = new_resume
|
129 |
+
|
130 |
# Convert HTML to PDF and save
|
131 |
HTML(string=html_content).write_pdf(output_pdf_file, stylesheets=['resumes/style.css'])
|
132 |
|
|
|
142 |
|
143 |
# Gather inputs
|
144 |
with gr.Row():
|
145 |
+
resume_input = gr.File(label="Upload Your Resume (Supported Files)")
|
146 |
jd_input = gr.Textbox(label="Paste the Job Description Here", lines=9, interactive=True, placeholder="Paste job description...")
|
147 |
|
148 |
run_button = gr.Button("Optimize Resume π€")
|
|
|
155 |
output_resume = gr.Textbox(label="Edit resume and export!", interactive=True)
|
156 |
export_button = gr.Button("Export Resume as PDF π")
|
157 |
export_result = gr.Markdown(label="Export Result")
|
158 |
+
|
159 |
# Event binding
|
160 |
run_button.click(process_resume, inputs=[resume_input, jd_input], outputs=[output_resume_md, output_resume, output_suggestions])
|
161 |
export_button.click(export_resume, inputs=[output_resume], outputs=[export_result])
|