Commit
·
3cfcf03
1
Parent(s):
bff8693
Update app.py
Browse files
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(
|
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
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
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 |
-
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
|
73 |
-
return
|
74 |
|
75 |
-
def ai(qa,category):
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
|
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
|