DreamStream-1 commited on
Commit
6779194
·
verified ·
1 Parent(s): 41f4bbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,14 +1,14 @@
 
 
1
  import spacy
2
  import nltk
3
  import gradio as gr
4
  import pandas as pd
5
  import re
6
  from fuzzywuzzy import fuzz
7
- from transformers import pipeline
8
  from nltk.corpus import stopwords
9
  from nltk.tokenize import word_tokenize
10
  from nltk.stem import WordNetLemmatizer
11
- import gemini
12
  import fitz # PyMuPDF
13
 
14
  # Initialize NLTK resources
@@ -26,8 +26,15 @@ except:
26
  subprocess.run(["python3", "-m", "spacy", "download", "en_core_web_sm"])
27
  nlp = spacy.load("en_core_web_sm")
28
 
29
- # Initialize Gemini model for text analysis
30
- gemini_model = pipeline('text-classification', model='google/gemini-1.5-flash')
 
 
 
 
 
 
 
31
 
32
  # Extract text from PDF using PyMuPDF
33
  def extract_text_from_pdf(pdf_path):
@@ -72,11 +79,16 @@ def calculate_match_percentage(resume_text, job_desc_text):
72
  match = fuzz.partial_ratio(resume_text, job_desc_text)
73
  return match
74
 
75
- # Use Gemini 1.5 to analyze text and extract job-related insights
76
  def gemini_analysis(text):
77
- """Use Gemini 1.5 to analyze text and extract insights like roles and skills."""
78
- analysis = gemini_model(text)
79
- return analysis[0]['label']
 
 
 
 
 
80
 
81
  # Process resumes and calculate match with job description
82
  def process_uploaded_resumes(resume_files: list, job_desc: str):
@@ -98,7 +110,7 @@ def process_uploaded_resumes(resume_files: list, job_desc: str):
98
  # Compare named entities between resume and job description
99
  entity_match = len(resume_entities.intersection(job_desc_entities)) / len(job_desc_entities) * 100
100
 
101
- # Use Gemini model to analyze job-related insights (optional)
102
  gemini_match = gemini_analysis(resume_text)
103
 
104
  # Calculate match percentage based on fuzzy matching
 
1
+ import os
2
+ import google.generativeai as genai
3
  import spacy
4
  import nltk
5
  import gradio as gr
6
  import pandas as pd
7
  import re
8
  from fuzzywuzzy import fuzz
 
9
  from nltk.corpus import stopwords
10
  from nltk.tokenize import word_tokenize
11
  from nltk.stem import WordNetLemmatizer
 
12
  import fitz # PyMuPDF
13
 
14
  # Initialize NLTK resources
 
26
  subprocess.run(["python3", "-m", "spacy", "download", "en_core_web_sm"])
27
  nlp = spacy.load("en_core_web_sm")
28
 
29
+ # Fetch the Google API key from Hugging Face secrets
30
+ google_api_key = os.getenv("GOOGLE_API_KEY")
31
+
32
+ # Check if the key is being fetched correctly
33
+ if google_api_key is None:
34
+ raise ValueError("Google API Key is missing from environment variables.")
35
+
36
+ # Configure the Gemini API with the secret key
37
+ genai.configure(api_key=google_api_key)
38
 
39
  # Extract text from PDF using PyMuPDF
40
  def extract_text_from_pdf(pdf_path):
 
79
  match = fuzz.partial_ratio(resume_text, job_desc_text)
80
  return match
81
 
82
+ # Use Gemini 1.5 Flash to analyze text and extract job-related insights
83
  def gemini_analysis(text):
84
+ """Use Gemini 1.5 Flash model to analyze text and extract insights like roles and skills."""
85
+ response = genai.generate_text(
86
+ model="gemini-1.5-flash", # Use the Flash model here
87
+ temperature=0.7,
88
+ max_output_tokens=512,
89
+ input_text=text
90
+ )
91
+ return response['text']
92
 
93
  # Process resumes and calculate match with job description
94
  def process_uploaded_resumes(resume_files: list, job_desc: str):
 
110
  # Compare named entities between resume and job description
111
  entity_match = len(resume_entities.intersection(job_desc_entities)) / len(job_desc_entities) * 100
112
 
113
+ # Use Gemini 1.5 Flash model to analyze job-related insights (optional)
114
  gemini_match = gemini_analysis(resume_text)
115
 
116
  # Calculate match percentage based on fuzzy matching