gperdrizet commited on
Commit
5af784b
Β·
verified Β·
1 Parent(s): c21a217

Updated logging configuration

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. 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
- logging.basicConfig(level=logging.INFO)
18
- logger = logging.getLogger(__name__)
19
-
20
-
21
- def process_inputs(linkedin_pdf, github_url, job_post_text, user_instructions):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- if github_result["status"] == "success":
72
- result += " βœ… GitHub list download successful\n\n"
73
- logger.info(
74
- "GitHub repositories retrieved successfully for %s",
75
- github_result['metadata']['username']
76
- )
77
 
78
- else:
79
- result += f" ❌ GitHub extraction failed: {github_result['message']}\n\n"
80
- logger.error("GitHub extraction failed: %s", github_result['message'])
81
- else:
82
- result += "❌ No GitHub profile URL provided\n\n"
83
- logger.info("No GitHub URL provided")
84
-
85
- # Process job post text
86
- if job_post_text and job_post_text.strip():
87
- result += "βœ… Job post text provided\n"
88
- logger.info("Job post text provided (%d characters)", len(job_post_text))
89
-
90
- summary = summarize_job_call(job_post_text.strip())
91
- result += " βœ… Job post summary generated\n"
92
- logger.info("Job post summary generated (%d characters)", len(summary))
93
-
94
- else:
95
- result += "❌ Job post not provided\n"
96
- logger.info("No job post text provided")
97
- summary = None
98
-
99
- # Process user instructions
100
- if user_instructions and user_instructions.strip():
101
- result += "βœ… Additional instructions provided\n"
102
- logger.info("User instructions provided (%d characters)", len(user_instructions))
103
-
104
- else:
105
- result += "ℹ️ No additional instructions provided\n"
106
- logger.info("No additional instructions provided")
107
-
108
- logger.info("Input processing completed")
109
-
110
- # Generate resume only if we have valid extraction result
111
- if extraction_result and extraction_result.get("status") == "success":
112
- try:
113
- _ = write_resume(extraction_result, user_instructions, summary)
114
- result += "\nβœ… Resume generated successfully\n"
115
- logger.info("Resume generation completed successfully")
116
-
117
- except Exception as e:
118
- result += f"\n❌ Resume generation failed: {str(e)}\n"
119
- logger.error("Resume generation failed: %s", str(e))
120
- else:
121
- result += "\n❌ Cannot generate resume: No valid LinkedIn data extracted\n"
122
- result += "Please ensure you upload a valid LinkedIn PDF export file.\n"
123
- logger.warning("Resume generation skipped - no valid LinkedIn data available")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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