deepakchawla-cb commited on
Commit
3cfcf03
·
1 Parent(s): bff8693

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -43
app.py CHANGED
@@ -20,65 +20,82 @@ from langchain.llms import OpenAI
20
  from langchain.chains import RetrievalQA
21
  from langchain.document_loaders import TextLoader
22
  from langchain.prompts import PromptTemplate
 
 
 
 
 
 
 
 
23
 
24
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
25
 
26
 
27
- def predict(file_obj):
28
- loader = UnstructuredPDFLoader(file_obj.orig_name)
29
- data = loader.load()
30
- text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
31
- texts = text_splitter.split_documents(data)
32
 
33
- embeddings = OpenAIEmbeddings()
34
- docsearch = Chroma.from_documents(texts, embeddings)
35
- qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="map_reduce", retriever=docsearch.as_retriever())
36
 
37
- prompt_template = """Ignore all previous instructions. You are the world's best interviewer now. I am going to give you a resume of a candidate. Analyze the resume in 4 categories: Education, Work Experience, Projects and Internships, Others including interests, skills etc. Be simple, direct and commanding. Start with greeting the candidate with a 2 line relatable introduction emphasizing your superiority. Ask the candidate if they have a particular company and a role that they want to apply for.
38
- If the candidate mentions either the company or the role, then ensure all questions that would be asked will are related to it.
39
- If they don't mention either the company or role clearly, then ignore this and move to the next step.
40
- Then, give a one line response acknowledging the candidate or if they are not clear about the company or the role then acknowledge positively that you would ask practice interview questions. Then ask the candidate topic would they like to start with. There are 4 categories of questions: educational background related, role related or technical questions, behavioral questions and HR or culture related questions. Here, the candidate will have to put an input.
41
- Now you will have to ask interview questions. Ensure the questions are good have test the candidate's knowledge. You can choose between longer case based questions, hypothetical questions or academic questions etc. as you deem fit.
42
- If the candidate types educational background related, ask it 3-4 most relevant questions related to their education based on their resume which are relevant for the role or the company.
43
- If the candidate types role related or technical related then ask accordingly. Here you can even ask a coding question or test their technical understanding etc.
44
- Similarly, do it for behavioral questions and HR or culture related questions. You can also be creative, funny, or show emotions at time.
45
  {context}
46
  Question: {question}
47
- Answer in possible questions for interview:"""
48
  PROMPT = PromptTemplate(
49
  template=prompt_template, input_variables=["context", "question"]
50
  )
51
  chain_type_kwargs = {"prompt": PROMPT}
52
- qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs)
53
- response = []
54
- category = ["Technical", "Education Background", "Behaviour", "Project Specific"]
55
- for value in category:
56
-
57
- response.append({value:ai(qa, value)})
58
-
59
- html_output = ""
60
- for obj in response:
61
- # Loop through the key-value pairs in the object
62
- for key, value in obj.items():
63
- value = re.sub(r'[\d\.]+', '', value)
64
- value_list = value.strip().split('\n')
65
- value_html = "<ol>"
66
- for item in value_list:
67
- value_html += "<li>{}</li>".format(item.strip())
68
- value_html += "</ol>"
69
- html_output += "<h2>{}</h2>".format(key)
70
- html_output += value_html
 
 
 
 
 
 
 
 
 
 
 
71
 
72
 
73
- return html_output
74
 
75
- def ai(qa,category):
76
- query = "please suggest "+ category +" interview questions"
77
- data = list(filter(None, qa.run(query).split('\n')))
78
- results = list(filter(lambda x: x != ' ', data))
79
- results = "\n".join(results)
80
 
81
- return results
82
 
83
  model = whisper.load_model("base")
84
  sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions")
@@ -146,6 +163,7 @@ def inference(audio, sentiment_option):
146
 
147
  sentiment_results = analyze_sentiment(result.text)
148
  print(result.text)
 
149
  sentiment_output = display_sentiment_results(sentiment_results, sentiment_option)
150
 
151
  return lang.upper(), result.text, sentiment_output
 
20
  from langchain.chains import RetrievalQA
21
  from langchain.document_loaders import TextLoader
22
  from langchain.prompts import PromptTemplate
23
+ from langchain.callbacks.stdout import StdOutCallbackHandler
24
+ from langchain.chat_models.openai import ChatOpenAI
25
+ from langchain.prompts.prompt import PromptTemplate
26
+
27
+ from langchain.llms import OpenAI
28
+ from langchain.prompts import PromptTemplate
29
+ from langchain.chains import LLMChain
30
+
31
 
32
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
33
 
34
 
35
+ def predict(text):
36
+ # loader = UnstructuredPDFLoader(file_obj.orig_name)
37
+ # data = loader.load()
38
+ # text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
39
+ # texts = text_splitter.split_documents(data)
40
 
41
+ # embeddings = OpenAIEmbeddings()
42
+ # docsearch = Chroma.from_documents(texts, embeddings)
43
+ # qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="map_reduce", retriever=docsearch.as_retriever())
44
 
45
+ prompt_template = """Ignore all previous instructions. You are the world's hearing aid company markerting agent.
46
+ I am going to give you a text of a customer. Analyze it and you have 4 products in list which you have to suggest to the customer:
47
+ ampli-mini it is mainly works for Maximum comfort and discretion, ampli-connect it is mainly works for Connected to the things you love,
48
+ ampli-energy it is mainly works for Full of energy, like you, ampli-easy it is mainly works for Allow yourself to hear well.
49
+ You can also be creative, funny, or show emotions at time.
50
+ also share the book a appointment link of your company https://www.amplifon.com/uk/book-an-appointment
 
 
51
  {context}
52
  Question: {question}
53
+ Product details:"""
54
  PROMPT = PromptTemplate(
55
  template=prompt_template, input_variables=["context", "question"]
56
  )
57
  chain_type_kwargs = {"prompt": PROMPT}
58
+ # qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs)
59
+
60
+
61
+ llm = OpenAI()
62
+ # prompt = PromptTemplate(
63
+ # input_variables=["product"],
64
+ # template="What is a good name for a company that makes {product}?",
65
+ # )
66
+ chain = LLMChain(llm=llm, prompt=PROMPT)
67
+ resp = chain.run(context=text)
68
+ print(resp)
69
+
70
+ # response = []
71
+ # category = ["ampli-mini", "ampli-connect", "ampli-energy", "ampli-easy"]
72
+ # for value in category:
73
+
74
+ # response.append({value:ai(qa, value)})
75
+
76
+ # html_output = ""
77
+ # for obj in response:
78
+ # # Loop through the key-value pairs in the object
79
+ # for key, value in obj.items():
80
+ # value = re.sub(r'[\d\.]+', '', value)
81
+ # value_list = value.strip().split('\n')
82
+ # value_html = "<ol>"
83
+ # for item in value_list:
84
+ # value_html += "<li>{}</li>".format(item.strip())
85
+ # value_html += "</ol>"
86
+ # html_output += "<h2>{}</h2>".format(key)
87
+ # html_output += value_html
88
 
89
 
90
+ return "<p>resp</p>"
91
 
92
+ # def ai(qa,category):
93
+ # query = "please suggest "+ category +" interview questions"
94
+ # data = list(filter(None, qa.run(query).split('\n')))
95
+ # results = list(filter(lambda x: x != ' ', data))
96
+ # results = "\n".join(results)
97
 
98
+ # return results
99
 
100
  model = whisper.load_model("base")
101
  sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions")
 
163
 
164
  sentiment_results = analyze_sentiment(result.text)
165
  print(result.text)
166
+ print(predict(result.text))
167
  sentiment_output = display_sentiment_results(sentiment_results, sentiment_option)
168
 
169
  return lang.upper(), result.text, sentiment_output