File size: 4,052 Bytes
9fec341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
from src.resume_parser import ResumeParser
from generate_questions.questions_generator import QuestionGenerator
import google.generativeai as genai
import os
from src.greetings import end_conversation,start_greeting
import json
from src.feedback import feed_back

genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
model = genai.GenerativeModel("gemini-pro")

chat = model.start_chat(history=[])
resume_parser = ResumeParser()
questions_generator = QuestionGenerator()


class ResumeUploader:
    def resume_upload(self):
        st.title("TalentScout - Hiring Assistant Chatbot")
        start_greeting()
        st.sidebar.title("Candidate Details")

        if "tech_stack" not in st.session_state:
            st.session_state.tech_stack = []
        if "questions" not in st.session_state:
            st.session_state.questions = {}
        if "answers" not in st.session_state:
            st.session_state.answers = {}

        uploaded_file = st.sidebar.file_uploader("Upload Resume (PDF):", type=["pdf"])
        if uploaded_file:
            candidate_details = resume_parser.parse(uploaded_file)
            st.success("Resume uploaded and processed successfully!")
            st.write("### Candidate Information")
            st.write(f"**Name:** {candidate_details['name']}")
            st.write(f"**Email:** {candidate_details['email']}")
            st.write(f"**Phone:** {candidate_details['phone']}")
            st.write(f"**Experience:** {candidate_details['experience']}")
            st.write(f"**Position:** {candidate_details['position']}")
            st.write(f"**Location:** {candidate_details['location']}")
            st.write(f"**Tech Stack:** {', '.join(candidate_details['tech_stack'])}")
            st.session_state.tech_stack = candidate_details["tech_stack"][:5]

        if st.session_state.tech_stack:
            st.write("**Based on your Top 5 skills ,we generate Technical Question , you need to answer the question .If you are ready  please click Generate Questions button**")
            if st.button("Generate Questions"):
                for tech in st.session_state.tech_stack:
                    tech = tech.strip()
                    if tech not in st.session_state.questions:
                        questions = questions_generator.generate_questions(chat, tech)
                        st.session_state.questions[tech] = questions.split("\n")
                        st.session_state.answers[tech] = [""] * len(st.session_state.questions[tech])

            # Display questions and answers
            if st.session_state.questions:
                for tech, questions in st.session_state.questions.items():
                    st.write(f"### Technical Questions for {tech}")
                    for idx, question in enumerate(questions):
                        st.write(f"{idx + 1}. {question}")
                        st.session_state.answers[tech][idx] = st.text_area(
                            f"Answer for Q{idx + 1} ({tech})",
                            value=st.session_state.answers[tech][idx],
                            key=f"answer_{tech}_{idx}",)

                if st.button("Submit Answers"):
                    # Combine questions and answers into a JSON format
                    greets = end_conversation()
                    st.write(greets)
                    output_data = []
                    for tech, questions in st.session_state.questions.items():
                        for idx, question in enumerate(questions):
                            output_data.append({
                                "tech": tech,
                                "question": question,
                                "answer": st.session_state.answers[tech][idx]
                            })

                    # Save as JSON file
                    json_filename = "questions_answers.json"
                    with open(json_filename, "w") as json_file:
                        json.dump(output_data, json_file, indent=4)
                feed_back()