Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- .gitattributes +1 -0
- Arial Unicode.ttf +3 -0
- app.py +109 -0
- requirements.txt +5 -0
- resume_null.pdf +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Arial[[:space:]]Unicode.ttf filter=lfs diff=lfs merge=lfs -text
|
Arial Unicode.ttf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:876af2cd4854644e7f3e7feb2f688997fdb3343c6df6693611209c9dfb47ccec
|
| 3 |
+
size 23278008
|
app.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from reportlab.pdfgen import canvas
|
| 2 |
+
from reportlab.pdfbase.ttfonts import TTFont
|
| 3 |
+
from reportlab.pdfbase import pdfmetrics
|
| 4 |
+
from PyPDF2 import PdfReader
|
| 5 |
+
from PyPDF2 import PdfWriter
|
| 6 |
+
import openai
|
| 7 |
+
import uuid
|
| 8 |
+
import os
|
| 9 |
+
import gradio as gr
|
| 10 |
+
|
| 11 |
+
# 確保字體文件和模板文件存在於同一目錄
|
| 12 |
+
pdfmetrics.registerFont(TTFont("ArialUnicode", "./Arial Unicode.ttf"))
|
| 13 |
+
|
| 14 |
+
def draw_data_on_template(template_path, name, email, phone, education, experience, skills, social_media):
|
| 15 |
+
try:
|
| 16 |
+
temp_pdf_path = f"./{uuid.uuid4()}_temp.pdf"
|
| 17 |
+
c = canvas.Canvas(temp_pdf_path)
|
| 18 |
+
c.setFont("ArialUnicode", 22)
|
| 19 |
+
c.drawString(15, 750, f"Name: {name}")
|
| 20 |
+
c.drawString(15, 680, f"Email: {email}")
|
| 21 |
+
c.drawString(15, 610, f"Phone: {phone}")
|
| 22 |
+
c.drawString(15, 540, f"Education: {education}")
|
| 23 |
+
c.drawString(15, 470, f"Work Experience: {experience}")
|
| 24 |
+
c.drawString(15, 340, f"Skills: {skills}")
|
| 25 |
+
c.drawString(15, 200, f"Social Media: {social_media}")
|
| 26 |
+
c.save()
|
| 27 |
+
|
| 28 |
+
# 加載模板 PDF
|
| 29 |
+
reader = PdfReader(template_path)
|
| 30 |
+
template_page = reader.pages[0]
|
| 31 |
+
content_reader = PdfReader(temp_pdf_path)
|
| 32 |
+
content_page = content_reader.pages[0]
|
| 33 |
+
template_page.merge_page(content_page)
|
| 34 |
+
|
| 35 |
+
merged_pdf_path = f"./{uuid.uuid4()}_merged.pdf"
|
| 36 |
+
writer = PdfWriter()
|
| 37 |
+
writer.add_page(template_page)
|
| 38 |
+
with open(merged_pdf_path, "wb") as output_file:
|
| 39 |
+
writer.write(output_file)
|
| 40 |
+
os.remove(temp_pdf_path)
|
| 41 |
+
return merged_pdf_path
|
| 42 |
+
except Exception as e:
|
| 43 |
+
return f"Error in Drawing Data on Template: {str(e)}"
|
| 44 |
+
|
| 45 |
+
def recommend_jobs(api_key, skills):
|
| 46 |
+
try:
|
| 47 |
+
openai.api_key = api_key
|
| 48 |
+
skills_list = [skill.strip() for skill in skills.split(",") if skill.strip()]
|
| 49 |
+
if not skills_list:
|
| 50 |
+
return "Error: No valid skills provided."
|
| 51 |
+
prompt = f"請用正體中文回覆,根據以下技能推薦適合的職位:{', '.join(skills_list)}"
|
| 52 |
+
response = openai.ChatCompletion.create(
|
| 53 |
+
model="gpt-4",
|
| 54 |
+
messages=[{"role": "user", "content": prompt}]
|
| 55 |
+
)
|
| 56 |
+
if not response.choices:
|
| 57 |
+
return "Error: OpenAI API returned no results."
|
| 58 |
+
return response.choices[0].message['content'].strip()
|
| 59 |
+
except Exception as e:
|
| 60 |
+
return f"Error in Job Recommendation: {str(e)}"
|
| 61 |
+
|
| 62 |
+
def validate_and_process(api_key, name, email, phone, education, experience, skills, social_media):
|
| 63 |
+
errors = []
|
| 64 |
+
if not name.strip():
|
| 65 |
+
errors.append("Name不能為空.")
|
| 66 |
+
if not email.strip():
|
| 67 |
+
errors.append("Email不能為空.")
|
| 68 |
+
if not phone.strip():
|
| 69 |
+
errors.append("Phone不能為空.")
|
| 70 |
+
if not education.strip():
|
| 71 |
+
errors.append("Education不能為空.")
|
| 72 |
+
if not skills.strip():
|
| 73 |
+
errors.append("Skills不能為空.")
|
| 74 |
+
|
| 75 |
+
if errors:
|
| 76 |
+
return None, "\n".join(errors), "請填寫完整後重試!"
|
| 77 |
+
|
| 78 |
+
template_path = "./resume_null.pdf" # 確保模板文件上傳至同一目錄
|
| 79 |
+
merged_pdf = draw_data_on_template(template_path, name, email, phone, education, experience, skills, social_media)
|
| 80 |
+
if isinstance(merged_pdf, str) and merged_pdf.startswith("Error"):
|
| 81 |
+
return None, merged_pdf, "Merging with template failed."
|
| 82 |
+
|
| 83 |
+
job_recommendations = recommend_jobs(api_key, skills)
|
| 84 |
+
if job_recommendations.startswith("Error"):
|
| 85 |
+
return merged_pdf, "Resume generated successfully!", job_recommendations
|
| 86 |
+
return merged_pdf, "Resume generated successfully!", job_recommendations
|
| 87 |
+
|
| 88 |
+
with gr.Blocks() as demo:
|
| 89 |
+
gr.Markdown("# 自動生成簡歷工具")
|
| 90 |
+
api_key = gr.Textbox(label="OpenAI API Key", placeholder="請輸入您的 OpenAI API Key", type="password")
|
| 91 |
+
name = gr.Textbox(label="Name(必填)", placeholder="例:王小明")
|
| 92 |
+
email = gr.Textbox(label="Email(必填)", placeholder="a1234567890@example.com")
|
| 93 |
+
phone = gr.Textbox(label="Phone(必填)", placeholder="0912345678")
|
| 94 |
+
education = gr.Textbox(label="Education(必填)", placeholder="例:學位、主修、學校")
|
| 95 |
+
experience = gr.Textbox(label="Work Experience", placeholder="例:實習、兼職工作")
|
| 96 |
+
skills = gr.Textbox(label="Skills(必填)", placeholder="例:Python, Teaching, Data Analysis (多項技能用,分隔)")
|
| 97 |
+
social_media = gr.Textbox(label="Social Media", placeholder="例:LinkedIn URL")
|
| 98 |
+
pdf_output = gr.File(label="Download Your Resume")
|
| 99 |
+
status = gr.Textbox(label="Status / Error", interactive=False)
|
| 100 |
+
job_recommendations = gr.Textbox(label="Recommended Jobs", interactive=False)
|
| 101 |
+
|
| 102 |
+
generate_button = gr.Button("Generate Resume & Recommend Jobs")
|
| 103 |
+
generate_button.click(
|
| 104 |
+
validate_and_process,
|
| 105 |
+
inputs=[api_key, name, email, phone, education, experience, skills, social_media],
|
| 106 |
+
outputs=[pdf_output, status, job_recommendations]
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
fpdf
|
| 3 |
+
openai==0.28.0
|
| 4 |
+
PyPDF2 >= 3.0.0
|
| 5 |
+
reportlab
|
resume_null.pdf
ADDED
|
Binary file (24.5 kB). View file
|
|
|