Snap_CV / app.py
Hamza1721's picture
Update app.py
9ad2646 verified
import gradio as gr
import json
import openai
import os
from dotenv import load_dotenv
os.getenv('openai.api_key')
load_dotenv()
# Function to generate CV content using OpenAI with Harvard template style
def generate_cv_content(user_data):
MODEL = "gpt-3.5-turbo"
try:
response = openai.ChatCompletion.create(
model=MODEL,
messages=[{
"role": "system",
"content": """provide assistance in creating a comprehensive CV in Harvard style format. Please follow these guidelines:
1. Start with a clear and concise personal statement summarizing my career objectives and unique qualifications.
2. List my educational background, starting with the most recent degree. Include the name of the institutions, degree titles, and the years attended.
3. Detail my professional experience, highlighting key responsibilities and achievements in each role. Organize this section in reverse chronological order.
4. Include a section for skills, making sure to emphasize those that are relevant to my career goals.
5. Add any relevant certifications, publications, or awards, with a focus on those that enhance my professional profile.
6. Ensure the CV is formatted neatly, with consistent font and spacing, and is easy to read.
7. Keep the language formal and professional throughout."""},
{"role": "user", "content": "Create a professional CV according to the following user data in Harvard template style: " + json.dumps(user_data)}
],
temperature=0.7,
)
# Print response in json to console
return response['choices'][0]['message']['content']
except Exception as e:
print("An error occurred: ", e)
return None
def process_data(name, email, phone, address, highest_education, skills, experience, achievements, linkedin, portfolio, applying_for):
# Create a dictionary to hold the data
cv_data = {
"Name": name,
"Email": email,
"Phone": phone,
"Address": address,
"Highest Education": highest_education.to_dict(orient='records'),
"Skills": skills,
"Experience": experience.to_dict(orient='records'),
"Achievements": achievements,
"LinkedIn Profile": linkedin,
"Portfolio Link": portfolio,
"Applying for Role": applying_for
}
# Write the dictionary to a JSON file
with open('app.json', 'w') as json_file:
json.dump(cv_data, json_file, indent=4)
# Return the response of generate_cv_content
return generate_cv_content(cv_data)
# Define the form components
name = gr.components.Textbox(label="Name")
email = gr.components.Textbox(label="Email")
phone = gr.components.Textbox(label="Phone Number")
address = gr.components.Textbox(label="Address")
highest_education = gr.components.DataFrame(
headers=["Qualification" , "Insititute", "Passing year", "Obtain marks", "Total marks"],
datatype=["str", "str", "number", "number", "number"],
col_count=(5, 'fixed'),
label="Education",
)
skills = gr.components.Textbox(label="Skills")
experience = gr.components.Dataframe(
headers=["Role", "Company", "Start Date", "End Date"],
label="Work Experience",
datatype=["str", "str", "date", "date"],
col_count=(4, 'fixed'), # to fix the number of columns
)
achievements = gr.components.Textbox(label="Key Achievements")
linkedin = gr.components.Textbox(label="LinkedIn Profile")
portfolio = gr.components.Textbox(label="Portfolio Link")
applying_for = gr.components.Textbox(label="Role Applying For")
# Create the interface
# Create the interface
demo = gr.Interface(
fn=process_data,
inputs=[name, email, phone, address, highest_education, skills, experience, achievements, linkedin, portfolio, applying_for],
outputs=gr.components.Textbox(label="Generated CV")
)
demo.launch()