rrrreddy commited on
Commit
f68f274
1 Parent(s): a4eaa45

getting response from cohere based on the resume and jd provided

Browse files
Files changed (5) hide show
  1. .gitignore +128 -0
  2. app.py +5 -0
  3. requirements.txt +3 -0
  4. src/get_response.py +31 -0
  5. src/main.py +64 -0
.gitignore ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the executable, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+
53
+ # Translations
54
+ *.mo
55
+ *.pot
56
+
57
+ # Django stuff:
58
+ *.log
59
+ local_settings.py
60
+ db.sqlite3
61
+ db.sqlite3-journal
62
+
63
+ # Flask stuff:
64
+ instance/
65
+ .webassets-cache
66
+
67
+ # Scrapy stuff:
68
+ .scrapy
69
+
70
+ # Sphinx documentation
71
+ docs/_build/
72
+
73
+ # PyBuilder
74
+ target/
75
+
76
+ # Jupyter Notebook
77
+ .ipynb_checkpoints
78
+
79
+ # pyenv
80
+ .python-version
81
+
82
+ # celery beat schedule file
83
+ celerybeat-schedule
84
+
85
+ # SageMath parsed files
86
+ *.sage.py
87
+
88
+ # Environments
89
+ .env
90
+ .venv
91
+ env/
92
+ venv/
93
+ ENV/
94
+ env.bak/
95
+ venv.bak/
96
+
97
+ # Spyder project settings
98
+ .spyderproject
99
+ .spyproject
100
+
101
+ # Rope project settings
102
+ .ropeproject
103
+
104
+ # mkdocs documentation
105
+ /site
106
+
107
+ # mypy
108
+ .mypy_cache/
109
+ .dmypy.json
110
+ dmypy.json
111
+
112
+ # Pyre type checker
113
+ .pyre/
114
+
115
+ # pytype static type analyzer
116
+ .pytype/
117
+
118
+ # profiling data
119
+ .prof
120
+
121
+ # Others
122
+ .idea/
123
+ .vscode/
124
+ *.swp
125
+ *.swo
126
+ *~
127
+
128
+ env
app.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from src.main import run_app
3
+
4
+ # Run the application
5
+ run_app()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ cohere
3
+ python-dotenv
src/get_response.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cohere
2
+ from dotenv import load_dotenv
3
+ import os
4
+
5
+ # Load environment variables from .env file
6
+ load_dotenv()
7
+
8
+ # Initialize the Cohere client with the API key from the environment variable
9
+ cohere_api_key = os.getenv('COHERE_API_KEY')
10
+ cohere_client = cohere.Client(cohere_api_key)
11
+
12
+ # Function to store the initial context (resume and job description)
13
+ def store_context(resume_text, job_description):
14
+ context = f"Resume:\n{resume_text}\n\nJob Description:\n{job_description}\n\n"
15
+ return context
16
+
17
+
18
+ # Function to answer questions based on the stored context and a new question
19
+ def answer_questions(context, question):
20
+ prompt = (
21
+ f"{context}"
22
+ f"Question:\n"
23
+ f"{question}\n\n"
24
+ "Answer:"
25
+ )
26
+ response = cohere_client.generate(
27
+ model='command-xlarge-nightly',
28
+ prompt=prompt,
29
+ max_tokens=500 # Adjust max_tokens to a higher value as needed
30
+ )
31
+ return response.generations[0].text.strip()
src/main.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from src.get_response import store_context, answer_questions
3
+
4
+ def initialize_session_state():
5
+ if "context" not in st.session_state:
6
+ st.session_state.context = None
7
+ if "qa_pairs" not in st.session_state:
8
+ st.session_state.qa_pairs = []
9
+
10
+ def input_resume_and_job_description():
11
+ st.subheader("Input Resume and Job Description")
12
+ resume_input = st.text_area("Enter your resume text:", height=200)
13
+ job_description_input = st.text_area("Enter the job description text:", height=200)
14
+
15
+ if st.button("Submit Resume and Job Description"):
16
+ if resume_input.strip() and job_description_input.strip():
17
+ st.session_state.context = store_context(resume_input, job_description_input)
18
+ st.session_state.qa_pairs = [] # Clear previous Q&A pairs when new context is submitted
19
+ st.success("Context stored successfully. You can now ask questions.")
20
+ st.experimental_rerun()
21
+ else:
22
+ st.warning("Please enter both the resume and the job description text.")
23
+
24
+ def input_question():
25
+ st.subheader("Ask Questions")
26
+ question_input = st.text_input("Enter a question based on the resume and job description:")
27
+
28
+ if st.button("Answer Question"):
29
+ if st.session_state.context and question_input.strip():
30
+ answer = answer_questions(st.session_state.context, question_input)
31
+ st.session_state.qa_pairs.insert(0, (question_input, answer)) # Insert at the beginning to keep the latest at the top
32
+ st.experimental_rerun()
33
+ else:
34
+ st.warning("Please enter a question.")
35
+
36
+ def display_qa_pairs():
37
+ if st.session_state.qa_pairs:
38
+ st.subheader("Questions and Answers:")
39
+ for i, (question, answer) in enumerate(st.session_state.qa_pairs):
40
+ st.write(f"**Q{i+1}:** {question}")
41
+ st.write(f"**A{i+1}:** {answer}")
42
+
43
+ def clear_context_and_qa():
44
+ if st.button("Clear Context and Q&A"):
45
+ st.session_state.context = None
46
+ st.session_state.qa_pairs = []
47
+ st.success("Context and Q&A cleared. Please enter new resume and job description.")
48
+ st.experimental_rerun()
49
+
50
+ def run_app():
51
+ st.title("Resume and Job Description Analyzer")
52
+ st.write("This app uses Cohere's NLP capabilities to answer questions based on your resume and job description.")
53
+
54
+ initialize_session_state()
55
+
56
+ if st.session_state.context is None:
57
+ input_resume_and_job_description()
58
+ else:
59
+ st.success("Context is already stored. You can ask questions based on it.")
60
+ input_question()
61
+ display_qa_pairs()
62
+ clear_context_and_qa()
63
+
64
+ st.write("Powered by Streamlit and Cohere")