Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 2 |
+
from langchain_core.messages import HumanMessage
|
| 3 |
+
from langchain_core.messages import AIMessage
|
| 4 |
+
from langchain.memory import ChatMessageHistory
|
| 5 |
+
from langchain_openai import AzureChatOpenAI
|
| 6 |
+
from pypdf import PdfReader
|
| 7 |
+
import os
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
# chat = AzureChatOpenAI(azure_deployment = "GPT-3")
|
| 11 |
+
|
| 12 |
+
def extract_text( pdf_path):
|
| 13 |
+
# creating a pdf reader object
|
| 14 |
+
reader = PdfReader(pdf_path)
|
| 15 |
+
all_text = ""
|
| 16 |
+
|
| 17 |
+
for page in reader.pages:
|
| 18 |
+
all_text += page.extract_text()
|
| 19 |
+
return all_text
|
| 20 |
+
|
| 21 |
+
def get_response( candidate, resume, jd, chat_history):
|
| 22 |
+
|
| 23 |
+
resume = extract_text(resume)
|
| 24 |
+
jd = extract_text(jd)
|
| 25 |
+
|
| 26 |
+
prompt = ChatPromptTemplate.from_messages(
|
| 27 |
+
[
|
| 28 |
+
(
|
| 29 |
+
"system",
|
| 30 |
+
"""Your Task is Perform as intelligent interviewer, Your Task is ask question to the resume's candidate by following candidate Answer.
|
| 31 |
+
at the end exit with greeting to the candidate.
|
| 32 |
+
**Ask question follow up on the candidate response. get chat history.**
|
| 33 |
+
""",
|
| 34 |
+
),
|
| 35 |
+
MessagesPlaceholder(variable_name="messages"),
|
| 36 |
+
]
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
chain = prompt | chat
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
answer = chain.invoke(
|
| 43 |
+
{
|
| 44 |
+
"messages": [
|
| 45 |
+
HumanMessage(
|
| 46 |
+
content=f" job description :{jd}\n Resume :{resume}"
|
| 47 |
+
),
|
| 48 |
+
AIMessage(content=f"Perform as intelligent interviewer, Your Task is ask question to the resume's candidate by following candidate Answer:"),
|
| 49 |
+
HumanMessage(content=candidate),
|
| 50 |
+
],
|
| 51 |
+
}
|
| 52 |
+
)
|
| 53 |
+
# print("INTERVIEWER :", answer.content)
|
| 54 |
+
# chat_history.append({"candidate":candidate,"interviewer":answer.content })
|
| 55 |
+
|
| 56 |
+
result = answer.content
|
| 57 |
+
chat_history.append({'candidate':candidate, "interviewer": result})
|
| 58 |
+
print("chat_history", chat_history)
|
| 59 |
+
return "", chat_history
|
| 60 |
+
|
| 61 |
+
def gradio_interface() -> None:
|
| 62 |
+
"""Create a Gradio interface for the chatbot."""
|
| 63 |
+
with gr.Blocks(css = "style.css" ,theme="freddyaboulton/test-blue") as demo:
|
| 64 |
+
|
| 65 |
+
gr.HTML("""<center class="darkblue" text-align:center;padding:30px;'><center>
|
| 66 |
+
<center><h1 class ="center" style="color:#fff">ADOPLE AI</h1></center>
|
| 67 |
+
<br><center><h1 style="color:#fff">Screening Assistant Chatbot</h1></center>""")
|
| 68 |
+
|
| 69 |
+
chatbot = gr.Chatbot()
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
with gr.Column(scale=1):
|
| 73 |
+
msg = gr.Textbox(label="Question")
|
| 74 |
+
|
| 75 |
+
with gr.Row():
|
| 76 |
+
with gr.Column(scale=0.15):
|
| 77 |
+
resume = gr.File(label="Resume")
|
| 78 |
+
with gr.Column(scale=0.15):
|
| 79 |
+
jd = gr.File(label="Job Description")
|
| 80 |
+
with gr.Column(scale=0.85):
|
| 81 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 82 |
+
|
| 83 |
+
msg.submit(get_response, [msg, chatbot, resume, jd], [msg, chatbot])
|
| 84 |
+
|
| 85 |
+
demo.launch(debug =True, share=True)
|
| 86 |
+
|
| 87 |
+
gradio_interface()
|