Nassiraaa commited on
Commit
04903e8
·
verified ·
1 Parent(s): 862275a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -39
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  from cv_analyzer import analyze_cv
4
  from cv_quality import CV
5
  from get_supabase import Supabase
 
6
 
7
  st.set_page_config(page_title="CV Analyzer", layout="wide")
8
  st.title('CV Analyzer')
@@ -10,61 +11,69 @@ st.title('CV Analyzer')
10
  # Initialize Supabase client
11
  supabase_client = Supabase().init_supabase_client()
12
 
 
 
 
 
13
  uploaded_file = st.file_uploader("Choose a CV file", type=['pdf', 'docx', 'txt'])
14
 
15
  if uploaded_file is not None:
16
  with st.spinner('Uploading and analyzing CV...'):
17
  # Upload file to Supabase storage
18
- file_path = f"cvs/{uploaded_file.name}"
19
- supabase_client.storage.from_("cvs").upload(file_path, uploaded_file.getvalue())
20
 
21
- # Get the public URL of the uploaded file
22
- file_url = supabase_client.storage.from_("cvs").get_public_url(file_path)
 
 
 
 
 
 
 
 
23
 
24
  # Create CV object with the file URL
25
  cv = CV(file_url)
26
  result = cv.analyse_cv_quality()
27
 
28
- # Optionally, delete the file after analysis
29
- # supabase_client.storage.from_("cvs").remove([file_path])
 
 
 
 
 
 
 
30
 
31
- if "error" in result:
32
- st.error(result["error"])
33
- else:
34
- # Display results (same as before)
35
- # Personal Information
36
- st.header("Personal Information")
37
- personal_info = result["personal_info"]
38
- st.json(personal_info)
39
- st.write(f"Personal Information Score: {personal_info['personal_info_score']}")
40
 
41
- # Detected Sections
42
- st.header("Detected Sections")
43
- st.write(result["detected_sections"])
44
- st.write(f"Section Detection Score: {result['section_detection_score']}")
45
 
46
- # Spelling and Grammar
47
- st.header("Spelling and Grammar")
48
- st.write(f"Error Percentage: {result['spelling_grammar_error_percentage']:.2f}%")
49
- st.write(f"Spelling and Grammar Score: {result['spelling_grammar_score']}")
 
50
 
51
- # Content Quality Analysis
52
- st.header("Content Quality Analysis")
53
- for section, evaluation in result['content_analysis'].items():
54
- st.subheader(section.capitalize())
55
- st.json(evaluation)
56
-
57
- st.write(f"Overall Content Quality Score: {result['overall_score']:.2f} / 10")
58
 
59
- # Total Score
60
- st.header("Total CV Score")
61
- total_score = (
62
- personal_info['personal_info_score'] +
63
- result['section_detection_score'] +
64
- result['spelling_grammar_score'] +
65
- result['overall_score']
66
- )
67
- st.write(f"Total Score: {total_score:.2f}")
68
 
69
  if __name__ == "__main__":
70
  st.sidebar.title("About")
 
3
  from cv_analyzer import analyze_cv
4
  from cv_quality import CV
5
  from get_supabase import Supabase
6
+ from datetime import datetime
7
 
8
  st.set_page_config(page_title="CV Analyzer", layout="wide")
9
  st.title('CV Analyzer')
 
11
  # Initialize Supabase client
12
  supabase_client = Supabase().init_supabase_client()
13
 
14
+ # Supabase storage details
15
+ BUCKET_NAME = "CVs UX"
16
+ SUPABASE_PROJECT_ID = "abjtqzgnrtsikkqgnqeg"
17
+
18
  uploaded_file = st.file_uploader("Choose a CV file", type=['pdf', 'docx', 'txt'])
19
 
20
  if uploaded_file is not None:
21
  with st.spinner('Uploading and analyzing CV...'):
22
  # Upload file to Supabase storage
23
+ file_path = f"{uploaded_file.name}"
 
24
 
25
+ with uploaded_file as f:
26
+ supabase_client.storage.from_(BUCKET_NAME).upload(
27
+ file=f,
28
+ path=file_path,
29
+ file_options={"cache-control": "3600", "upsert": "true"}
30
+ )
31
+
32
+ # Construct the public URL of the uploaded file
33
+ timestamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
34
+ file_url = f"https://{SUPABASE_PROJECT_ID}.supabase.co/storage/v1/object/public/{BUCKET_NAME}/{file_path}?t={timestamp}"
35
 
36
  # Create CV object with the file URL
37
  cv = CV(file_url)
38
  result = cv.analyse_cv_quality()
39
 
40
+ if "error" in result:
41
+ st.error(result["error"])
42
+ else:
43
+ # Display results
44
+ # Personal Information
45
+ st.header("Personal Information")
46
+ personal_info = result["personal_info"]
47
+ st.json(personal_info)
48
+ st.write(f"Personal Information Score: {personal_info['personal_info_score']}")
49
 
50
+ # Detected Sections
51
+ st.header("Detected Sections")
52
+ st.write(result["detected_sections"])
53
+ st.write(f"Section Detection Score: {result['section_detection_score']}")
 
 
 
 
 
54
 
55
+ # Spelling and Grammar
56
+ st.header("Spelling and Grammar")
57
+ st.write(f"Error Percentage: {result['spelling_grammar_error_percentage']:.2f}%")
58
+ st.write(f"Spelling and Grammar Score: {result['spelling_grammar_score']}")
59
 
60
+ # Content Quality Analysis
61
+ st.header("Content Quality Analysis")
62
+ for section, evaluation in result['content_analysis'].items():
63
+ st.subheader(section.capitalize())
64
+ st.json(evaluation)
65
 
66
+ st.write(f"Overall Content Quality Score: {result['overall_score']:.2f} / 10")
 
 
 
 
 
 
67
 
68
+ # Total Score
69
+ st.header("Total CV Score")
70
+ total_score = (
71
+ personal_info['personal_info_score'] +
72
+ result['section_detection_score'] +
73
+ result['spelling_grammar_score'] +
74
+ result['overall_score']
75
+ )
76
+ st.write(f"Total Score: {total_score:.2f}")
77
 
78
  if __name__ == "__main__":
79
  st.sidebar.title("About")