File size: 3,454 Bytes
63d1ff6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3919f1f
 
 
 
 
 
63d1ff6
 
5d2b73b
63d1ff6
 
5ad0f32
63d1ff6
 
5ad0f32
63d1ff6
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
import os
import openai
import PyPDF2
import gradio as gr
import docx

class CourseGenarator:
    def __init__(self):
        openai.api_key = os.getenv("OPENAI_API_KEY")

    def extract_text_from_file(self,file_path):
        # Get the file extension
        file_extension = os.path.splitext(file_path)[1]

        if file_extension == '.pdf':
            with open(file_path, 'rb') as file:
                # Create a PDF file reader object
                reader = PyPDF2.PdfFileReader(file)

                # Create an empty string to hold the extracted text
                extracted_text = ""

                # Loop through each page in the PDF and extract the text
                for page_number in range(reader.getNumPages()):
                    page = reader.getPage(page_number)
                    extracted_text += page.extractText()
            return extracted_text

        elif file_extension == '.txt':
            with open(file_path, 'r') as file:
                # Just read the entire contents of the text file
                return file.read()

        elif file_extension == '.docx':
              doc = docx.Document(file_path)
              text = []
              for paragraph in doc.paragraphs:
                  text.append(paragraph.text)
              return '\n'.join(text)

        else:
            return "Unsupported file type"

    def response(self,resume_path):
        resume_path = resume_path.name
        resume = self.extract_text_from_file(resume_path)


        # Define the prompt or input for the model
        prompt = f"""Analyze the resume to generate online courses with website links to improve skills following resume delimitted by triple backticks. Generate atmost five courses.
                     result format should be:
                     course:[course].
                     website link:[website link]
                     ```{resume}```
                  """

        # Generate a response from the GPT-3 model
        response = openai.Completion.create(
            engine='text-davinci-003',
            prompt=prompt,
            max_tokens=200,
            temperature=0,
            n=1,
            stop=None,
        )

        # Extract the generated text from the API response
        generated_text = response.choices[0].text.strip()

        return generated_text

    def gradio_interface(self):
      with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-gray') as app:
            gr.HTML("""<center class="darkblue" style='background-color:rgb(0,1,36); text-align:center;padding:30px;'><center>
            <img class="leftimage" align="left" src="https://companieslogo.com/img/orig/RAND.AS_BIG-0f1935a4.png?t=1651813778" alt="Image" width="210" height="210">
            <h1 class ="center" style="color:#fff">ADOPLE AI</h1></center>
            <br><center><h1 style="color:#fff">Candidate Assessment and Communication</h1></center>""")
          
            with gr.Row(elem_id="col-container"):
              with gr.Column():
                resume = gr.File(label="Resume",elem_classes="heightfit")

              with gr.Column():
                analyse = gr.Button("Find Courses")

              with gr.Column():
                result = gr.Textbox(label="Suggested Cources",lines=8)

            analyse.click(self.response, [resume], result)
            print(result)

      app.launch()

ques = CourseGenarator()
ques.gradio_interface()