Spaces:
Sleeping
Sleeping
Updated logging configuration
Browse files- .gitignore +1 -0
- functions/gradio.py +122 -95
.gitignore
CHANGED
@@ -2,5 +2,6 @@ __pycache__
|
|
2 |
.vscode
|
3 |
.venv
|
4 |
.env
|
|
|
5 |
data
|
6 |
inference_endpoints
|
|
|
2 |
.vscode
|
3 |
.venv
|
4 |
.env
|
5 |
+
logs
|
6 |
data
|
7 |
inference_endpoints
|
functions/gradio.py
CHANGED
@@ -8,17 +8,37 @@ import logging
|
|
8 |
from pathlib import Path
|
9 |
from functions.linkedin_resume import extract_text_from_linkedin_pdf
|
10 |
from functions.github import get_github_repositories
|
11 |
-
from functions.job_call import summarize_job_call
|
12 |
-
from functions.writer_agent import write_resume
|
13 |
|
14 |
# pylint: disable=broad-exception-caught
|
15 |
|
16 |
# Set up logging
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
"""
|
23 |
Process the input files and URLs from the Gradio interface.
|
24 |
|
@@ -31,96 +51,103 @@ def process_inputs(linkedin_pdf, github_url, job_post_text, user_instructions):
|
|
31 |
Returns:
|
32 |
str: Formatted output with file and URL information
|
33 |
"""
|
34 |
-
result = ""
|
35 |
-
extraction_result = None
|
36 |
-
logger.info("Processing user inputs from Gradio interface")
|
37 |
-
|
38 |
-
# Process LinkedIn PDF file
|
39 |
-
if linkedin_pdf is not None:
|
40 |
-
file_path = linkedin_pdf.name
|
41 |
-
file_display_name = Path(file_path).name
|
42 |
-
|
43 |
-
result += "β
LinkedIn Resume PDF provided\n"
|
44 |
-
logger.info("Processing LinkedIn PDF: %s", file_display_name)
|
45 |
-
|
46 |
-
# Extract and structure text from the PDF
|
47 |
-
extraction_result = extract_text_from_linkedin_pdf(file_path)
|
48 |
-
|
49 |
-
if extraction_result["status"] == "success":
|
50 |
-
result += " β
Text extraction successful\n\n"
|
51 |
-
logger.info("LinkedIn PDF text extraction successful")
|
52 |
-
|
53 |
-
elif extraction_result["status"] == "warning":
|
54 |
-
result += f" β οΈ Text extraction: {extraction_result['message']}\n\n"
|
55 |
-
logger.warning("LinkedIn PDF extraction warning: %s", extraction_result['message'])
|
56 |
-
else:
|
57 |
-
result += f" β Text extraction failed: {extraction_result['message']}\n\n"
|
58 |
-
logger.error("LinkedIn PDF extraction failed: %s", extraction_result['message'])
|
59 |
-
else:
|
60 |
-
result += "β No LinkedIn resume PDF file uploaded\n\n"
|
61 |
-
logger.info("No LinkedIn PDF file provided")
|
62 |
-
|
63 |
-
# Process GitHub profile
|
64 |
-
if github_url and github_url.strip():
|
65 |
-
result += "β
GitHub Profile URL provided\n"
|
66 |
-
logger.info("Processing GitHub URL: %s", github_url.strip())
|
67 |
-
|
68 |
-
# Retrieve repositories from GitHub
|
69 |
-
github_result = get_github_repositories(github_url.strip())
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
#
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
return result
|
126 |
|
|
|
8 |
from pathlib import Path
|
9 |
from functions.linkedin_resume import extract_text_from_linkedin_pdf
|
10 |
from functions.github import get_github_repositories
|
11 |
+
# from functions.job_call import summarize_job_call
|
12 |
+
# from functions.writer_agent import write_resume
|
13 |
|
14 |
# pylint: disable=broad-exception-caught
|
15 |
|
16 |
# Set up logging
|
17 |
+
# Create logs directory if it doesn't exist
|
18 |
+
logs_dir = Path(__file__).parent.parent / "logs"
|
19 |
+
logs_dir.mkdir(exist_ok=True)
|
20 |
+
|
21 |
+
# Strip extraneous handlers
|
22 |
+
for handler in logging.root.handlers[:]:
|
23 |
+
logging.root.removeHandler(handler)
|
24 |
+
|
25 |
+
# Configure logging to write to file and console
|
26 |
+
logging.basicConfig(
|
27 |
+
level=logging.INFO,
|
28 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
29 |
+
handlers=[
|
30 |
+
logging.FileHandler(logs_dir / "gradio.log"),
|
31 |
+
logging.StreamHandler() # Also log to console
|
32 |
+
]
|
33 |
+
)
|
34 |
+
|
35 |
+
|
36 |
+
def process_inputs(
|
37 |
+
linkedin_pdf_path: str = None,
|
38 |
+
github_url: str = None,
|
39 |
+
job_post_text: str = None,
|
40 |
+
user_instructions: str = None
|
41 |
+
):
|
42 |
"""
|
43 |
Process the input files and URLs from the Gradio interface.
|
44 |
|
|
|
51 |
Returns:
|
52 |
str: Formatted output with file and URL information
|
53 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
logger = logging.getLogger(f'{__name__}.process_inputs')
|
56 |
+
logger.info("LinkedIn PDF: %s", linkedin_pdf_path)
|
57 |
+
logger.info("GitHub URL: %s", github_url)
|
58 |
+
logger.info("Job post: %s", job_post_text[:100])
|
59 |
+
logger.info("User instructions: %s", user_instructions[:100] if user_instructions else "None")
|
60 |
+
result = ""
|
61 |
|
62 |
+
# extraction_result = None
|
63 |
+
# logger.info("Processing user inputs from Gradio interface")
|
64 |
+
|
65 |
+
# # Process LinkedIn PDF file
|
66 |
+
# if linkedin_pdf is not None:
|
67 |
+
# file_path = linkedin_pdf.name
|
68 |
+
# file_display_name = Path(file_path).name
|
69 |
+
|
70 |
+
# result += "β
LinkedIn Resume PDF provided\n"
|
71 |
+
# logger.info("Processing LinkedIn PDF: %s", file_display_name)
|
72 |
+
|
73 |
+
# # Extract and structure text from the PDF
|
74 |
+
# extraction_result = extract_text_from_linkedin_pdf(file_path)
|
75 |
+
|
76 |
+
# if extraction_result["status"] == "success":
|
77 |
+
# result += " β
Text extraction successful\n\n"
|
78 |
+
# logger.info("LinkedIn PDF text extraction successful")
|
79 |
+
|
80 |
+
# elif extraction_result["status"] == "warning":
|
81 |
+
# result += f" β οΈ Text extraction: {extraction_result['message']}\n\n"
|
82 |
+
# logger.warning("LinkedIn PDF extraction warning: %s", extraction_result['message'])
|
83 |
+
# else:
|
84 |
+
# result += f" β Text extraction failed: {extraction_result['message']}\n\n"
|
85 |
+
# logger.error("LinkedIn PDF extraction failed: %s", extraction_result['message'])
|
86 |
+
# else:
|
87 |
+
# result += "β No LinkedIn resume PDF file uploaded\n\n"
|
88 |
+
# logger.info("No LinkedIn PDF file provided")
|
89 |
+
|
90 |
+
# # Process GitHub profile
|
91 |
+
# if github_url and github_url.strip():
|
92 |
+
# result += "β
GitHub Profile URL provided\n"
|
93 |
+
# logger.info("Processing GitHub URL: %s", github_url.strip())
|
94 |
+
|
95 |
+
# # Retrieve repositories from GitHub
|
96 |
+
# github_result = get_github_repositories(github_url.strip())
|
97 |
+
|
98 |
+
# if github_result["status"] == "success":
|
99 |
+
# result += " β
GitHub list download successful\n\n"
|
100 |
+
# logger.info(
|
101 |
+
# "GitHub repositories retrieved successfully for %s",
|
102 |
+
# github_result['metadata']['username']
|
103 |
+
# )
|
104 |
+
|
105 |
+
# else:
|
106 |
+
# result += f" β GitHub extraction failed: {github_result['message']}\n\n"
|
107 |
+
# logger.error("GitHub extraction failed: %s", github_result['message'])
|
108 |
+
# else:
|
109 |
+
# result += "β No GitHub profile URL provided\n\n"
|
110 |
+
# logger.info("No GitHub URL provided")
|
111 |
+
|
112 |
+
# # Process job post text
|
113 |
+
# if job_post_text and job_post_text.strip():
|
114 |
+
# result += "β
Job post text provided\n"
|
115 |
+
# logger.info("Job post text provided (%d characters)", len(job_post_text))
|
116 |
+
|
117 |
+
# summary = summarize_job_call(job_post_text.strip())
|
118 |
+
# result += " β
Job post summary generated\n"
|
119 |
+
# logger.info("Job post summary generated (%d characters)", len(summary))
|
120 |
+
|
121 |
+
# else:
|
122 |
+
# result += "β Job post not provided\n"
|
123 |
+
# logger.info("No job post text provided")
|
124 |
+
# summary = None
|
125 |
+
|
126 |
+
# # Process user instructions
|
127 |
+
# if user_instructions and user_instructions.strip():
|
128 |
+
# result += "β
Additional instructions provided\n"
|
129 |
+
# logger.info("User instructions provided (%d characters)", len(user_instructions))
|
130 |
+
|
131 |
+
# else:
|
132 |
+
# result += "βΉοΈ No additional instructions provided\n"
|
133 |
+
# logger.info("No additional instructions provided")
|
134 |
+
|
135 |
+
# logger.info("Input processing completed")
|
136 |
+
|
137 |
+
# # Generate resume only if we have valid extraction result
|
138 |
+
# if extraction_result and extraction_result.get("status") == "success":
|
139 |
+
# try:
|
140 |
+
# _ = write_resume(extraction_result, user_instructions, summary)
|
141 |
+
# result += "\nβ
Resume generated successfully\n"
|
142 |
+
# logger.info("Resume generation completed successfully")
|
143 |
+
|
144 |
+
# except Exception as e:
|
145 |
+
# result += f"\nβ Resume generation failed: {str(e)}\n"
|
146 |
+
# logger.error("Resume generation failed: %s", str(e))
|
147 |
+
# else:
|
148 |
+
# result += "\nβ Cannot generate resume: No valid LinkedIn data extracted\n"
|
149 |
+
# result += "Please ensure you upload a valid LinkedIn PDF export file.\n"
|
150 |
+
# logger.warning("Resume generation skipped - no valid LinkedIn data available")
|
151 |
|
152 |
return result
|
153 |
|