Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
| 2 |
import litellm
|
| 3 |
from crewai import Agent, Task, Crew, Process
|
| 4 |
from crewai_tools import SerperDevTool
|
|
@@ -6,12 +9,14 @@ import pdfplumber
|
|
| 6 |
from docx import Document
|
| 7 |
import gradio as gr
|
| 8 |
|
|
|
|
|
|
|
| 9 |
# Set up API keys
|
| 10 |
litellm.api_key = "AIzaSyAlNlvB2unkbmkL6zweKVkjYEOVqIgovw4"
|
| 11 |
os.environ['SERPER_API_KEY'] = "d9295b6ec268aad1fa375484f1e3ce556329973d"
|
| 12 |
|
| 13 |
# Define the LLM
|
| 14 |
-
llm = "gemini/gemini-1.5-flash-exp-0827"
|
| 15 |
|
| 16 |
# Initialize the tool for internet searching capabilities
|
| 17 |
tool = SerperDevTool()
|
|
@@ -23,10 +28,11 @@ cv_analysis_agent = Agent(
|
|
| 23 |
verbose=True,
|
| 24 |
memory=True,
|
| 25 |
backstory=(
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
tools=[tool],
|
| 31 |
llm=llm,
|
| 32 |
allow_delegation=True
|
|
@@ -35,12 +41,14 @@ cv_analysis_agent = Agent(
|
|
| 35 |
# Create the Portfolio Generation Agent
|
| 36 |
portfolio_generation_agent = Agent(
|
| 37 |
role='Portfolio Generator',
|
| 38 |
-
goal='Generate a
|
| 39 |
verbose=True,
|
| 40 |
memory=True,
|
| 41 |
backstory=(
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
),
|
| 45 |
tools=[tool],
|
| 46 |
llm=llm,
|
|
@@ -50,29 +58,28 @@ portfolio_generation_agent = Agent(
|
|
| 50 |
# Research task for CV analysis
|
| 51 |
cv_analysis_task = Task(
|
| 52 |
description=(
|
| 53 |
-
"Analyze the provided {cv} and
|
| 54 |
-
"and
|
| 55 |
),
|
| 56 |
-
expected_output='A summary of skills, experiences, and
|
| 57 |
tools=[tool],
|
| 58 |
agent=cv_analysis_agent,
|
| 59 |
)
|
| 60 |
|
|
|
|
| 61 |
# Writing task for portfolio generation with enhanced UI requirements
|
|
|
|
| 62 |
portfolio_task = Task(
|
| 63 |
description=(
|
| 64 |
-
"Generate a
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
"
|
| 68 |
-
"but provide everything embedded in the HTML file. "
|
| 69 |
-
"The output should be a complete HTML document starting from <html> to </html>, ready to deploy."
|
| 70 |
),
|
| 71 |
-
expected_output='A complete HTML
|
| 72 |
tools=[tool],
|
| 73 |
agent=portfolio_generation_agent,
|
| 74 |
-
async_execution=
|
| 75 |
-
output_file='portfolio.html' # Output as HTML file
|
| 76 |
)
|
| 77 |
|
| 78 |
# Function to read CV from PDF or DOCX file
|
|
@@ -100,8 +107,7 @@ crew = Crew(
|
|
| 100 |
process=Process.sequential,
|
| 101 |
)
|
| 102 |
|
| 103 |
-
|
| 104 |
-
import re
|
| 105 |
|
| 106 |
# Function to process CV and generate portfolio
|
| 107 |
def process_cv(file):
|
|
@@ -116,28 +122,50 @@ def process_cv(file):
|
|
| 116 |
html_output = str(result)
|
| 117 |
|
| 118 |
# Use replace to remove '''html''' and ''' from the output
|
| 119 |
-
clean_html_output = html_output.replace("
|
| 120 |
|
| 121 |
return clean_html_output # Return the cleaned HTML
|
| 122 |
except Exception as e:
|
| 123 |
return f"Error: {e}"
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
|
|
|
| 138 |
|
| 139 |
-
#
|
| 140 |
-
process_button.click(fn=process_cv, inputs=cv_input, outputs=output_textbox)
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from google.colab import userdata
|
| 5 |
import litellm
|
| 6 |
from crewai import Agent, Task, Crew, Process
|
| 7 |
from crewai_tools import SerperDevTool
|
|
|
|
| 9 |
from docx import Document
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
+
|
| 13 |
+
|
| 14 |
# Set up API keys
|
| 15 |
litellm.api_key = "AIzaSyAlNlvB2unkbmkL6zweKVkjYEOVqIgovw4"
|
| 16 |
os.environ['SERPER_API_KEY'] = "d9295b6ec268aad1fa375484f1e3ce556329973d"
|
| 17 |
|
| 18 |
# Define the LLM
|
| 19 |
+
llm = "gemini/gemini-1.5-flash-exp-0827"
|
| 20 |
|
| 21 |
# Initialize the tool for internet searching capabilities
|
| 22 |
tool = SerperDevTool()
|
|
|
|
| 28 |
verbose=True,
|
| 29 |
memory=True,
|
| 30 |
backstory=(
|
| 31 |
+
"You are an expert CV Analyzer with a keen eye for detail. Your role is to meticulously examine the provided CV, "
|
| 32 |
+
"identifying and extracting key skills, experiences, accomplishments, and areas for improvement. "
|
| 33 |
+
"Your analysis should highlight strengths and suggest enhancements that would make the portfolio more competitive."
|
| 34 |
+
),
|
| 35 |
+
|
| 36 |
tools=[tool],
|
| 37 |
llm=llm,
|
| 38 |
allow_delegation=True
|
|
|
|
| 41 |
# Create the Portfolio Generation Agent
|
| 42 |
portfolio_generation_agent = Agent(
|
| 43 |
role='Portfolio Generator',
|
| 44 |
+
goal='Generate a professional HTML/CSS/JS responsive landing portfolio webpage based on {cv} analysis.',
|
| 45 |
verbose=True,
|
| 46 |
memory=True,
|
| 47 |
backstory=(
|
| 48 |
+
"As a Responsive Portfolio Generator, your expertise lies in creating visually appealing and user-friendly web pages. "
|
| 49 |
+
"Based on the CV analysis, you will generate a professional HTML/CSS/JS portfolio. "
|
| 50 |
+
"Ensure the design reflects the individual's strengths and experiences while incorporating effective functionality. "
|
| 51 |
+
"Consider responsiveness, color schemes, and navigation for an optimal user experience."
|
| 52 |
),
|
| 53 |
tools=[tool],
|
| 54 |
llm=llm,
|
|
|
|
| 58 |
# Research task for CV analysis
|
| 59 |
cv_analysis_task = Task(
|
| 60 |
description=(
|
| 61 |
+
"Analyze the provided {cv} in detail. Identify and summarize key skills, experiences, and notable accomplishments. "
|
| 62 |
+
"Highlight educational background and suggest potential enhancements to improve the overall presentation and competitiveness of the CV."
|
| 63 |
),
|
| 64 |
+
expected_output='A detailed summary of skills, experiences, accomplishments, and improvement suggestions formatted for a portfolio.',
|
| 65 |
tools=[tool],
|
| 66 |
agent=cv_analysis_agent,
|
| 67 |
)
|
| 68 |
|
| 69 |
+
|
| 70 |
# Writing task for portfolio generation with enhanced UI requirements
|
| 71 |
+
|
| 72 |
portfolio_task = Task(
|
| 73 |
description=(
|
| 74 |
+
"Generate a responsive HTML/CSS portfolio webpage based on the given CV analysis. "
|
| 75 |
+
"Include a navbar with the individual's name, and sections for skills, projects, experiences, certifications, and contact information. "
|
| 76 |
+
"Ensure the layout is clean and visually appealing with a light/dark theme toggle option. "
|
| 77 |
+
"Embed CSS/JS directly into the HTML for easy deployment, and optimize for both desktop and mobile viewing."
|
|
|
|
|
|
|
| 78 |
),
|
| 79 |
+
expected_output='A complete and responsive HTML document ready for deployment, showcasing the individual’s strengths.',
|
| 80 |
tools=[tool],
|
| 81 |
agent=portfolio_generation_agent,
|
| 82 |
+
async_execution=True,
|
|
|
|
| 83 |
)
|
| 84 |
|
| 85 |
# Function to read CV from PDF or DOCX file
|
|
|
|
| 107 |
process=Process.sequential,
|
| 108 |
)
|
| 109 |
|
| 110 |
+
|
|
|
|
| 111 |
|
| 112 |
# Function to process CV and generate portfolio
|
| 113 |
def process_cv(file):
|
|
|
|
| 122 |
html_output = str(result)
|
| 123 |
|
| 124 |
# Use replace to remove '''html''' and ''' from the output
|
| 125 |
+
clean_html_output = html_output.replace("```html", '').replace("```", '').strip()
|
| 126 |
|
| 127 |
return clean_html_output # Return the cleaned HTML
|
| 128 |
except Exception as e:
|
| 129 |
return f"Error: {e}"
|
| 130 |
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def save_html_to_file(html_content):
|
| 135 |
+
output_file_path = "Portfolio_generated_by_FiftyBit.html"
|
| 136 |
+
with open(output_file_path, "w") as f:
|
| 137 |
+
f.write(html_content)
|
| 138 |
+
return output_file_path
|
| 139 |
+
|
| 140 |
+
def upload_file(filepath):
|
| 141 |
+
name = Path(filepath).name
|
| 142 |
+
html_content = process_cv(filepath) # Get HTML content from the CV
|
| 143 |
+
|
| 144 |
+
clean_html_output = html_content.replace("```html", '').replace("```", '').strip()
|
| 145 |
+
gr.Markdown("# Preview of Your Portfolio:")
|
| 146 |
+
# Save the HTML content to a file
|
| 147 |
+
file_path = save_html_to_file(clean_html_output)
|
| 148 |
|
| 149 |
+
return clean_html_output, gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download Code", value=file_path, visible=True)
|
| 150 |
+
|
| 151 |
+
def download_file():
|
| 152 |
+
return [gr.UploadButton(label=f"Regenerate", visible=True), gr.DownloadButton(visible=False)]
|
| 153 |
+
|
| 154 |
+
with gr.Blocks() as demo:
|
| 155 |
+
gr.Markdown("# CV-2-Portfolio Site Generator")
|
| 156 |
+
gr.Markdown("Upload your CV in PDF or DOCX format for analysis and portfolio webpage generation.")
|
| 157 |
|
| 158 |
+
|
| 159 |
+
u = gr.UploadButton("Upload CV (.pdf or .docx)", file_count="single")
|
| 160 |
+
d = gr.DownloadButton("Download Portfolio", visible=False)
|
| 161 |
|
| 162 |
+
output_preview = gr.HTML(label="Webpage Preview" , value="<style>iframe { width: 100%; height: 600px; }</style><iframe srcdoc='Portfolio_generated_by_FiftyBit.html'></iframe></style>" ) # HTML output for preview
|
|
|
|
| 163 |
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# Connect the upload button to the upload_file function
|
| 167 |
+
u.upload(upload_file, u, [output_preview, u, d])
|
| 168 |
+
|
| 169 |
+
# Handle download button click
|
| 170 |
+
d.click(download_file, None, [u, d])
|
| 171 |
+
demo.launch(debug=True)
|