robertselvam's picture
Create app.py
fd1d045 verified
raw
history blame
2.99 kB
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.messages import HumanMessage
from langchain_core.messages import AIMessage
from langchain.memory import ChatMessageHistory
from langchain_openai import AzureChatOpenAI
from pypdf import PdfReader
import os
import gradio as gr
# chat = AzureChatOpenAI(azure_deployment = "GPT-3")
def extract_text( pdf_path):
# creating a pdf reader object
reader = PdfReader(pdf_path)
all_text = ""
for page in reader.pages:
all_text += page.extract_text()
return all_text
def get_response( candidate, resume, jd, chat_history):
resume = extract_text(resume)
jd = extract_text(jd)
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"""Your Task is Perform as intelligent interviewer, Your Task is ask question to the resume's candidate by following candidate Answer.
at the end exit with greeting to the candidate.
**Ask question follow up on the candidate response. get chat history.**
""",
),
MessagesPlaceholder(variable_name="messages"),
]
)
chain = prompt | chat
answer = chain.invoke(
{
"messages": [
HumanMessage(
content=f" job description :{jd}\n Resume :{resume}"
),
AIMessage(content=f"Perform as intelligent interviewer, Your Task is ask question to the resume's candidate by following candidate Answer:"),
HumanMessage(content=candidate),
],
}
)
# print("INTERVIEWER :", answer.content)
# chat_history.append({"candidate":candidate,"interviewer":answer.content })
result = answer.content
chat_history.append({'candidate':candidate, "interviewer": result})
print("chat_history", chat_history)
return "", chat_history
def gradio_interface() -> None:
"""Create a Gradio interface for the chatbot."""
with gr.Blocks(css = "style.css" ,theme="freddyaboulton/test-blue") as demo:
gr.HTML("""<center class="darkblue" text-align:center;padding:30px;'><center>
<center><h1 class ="center" style="color:#fff">ADOPLE AI</h1></center>
<br><center><h1 style="color:#fff">Screening Assistant Chatbot</h1></center>""")
chatbot = gr.Chatbot()
with gr.Row():
with gr.Column(scale=1):
msg = gr.Textbox(label="Question")
with gr.Row():
with gr.Column(scale=0.15):
resume = gr.File(label="Resume")
with gr.Column(scale=0.15):
jd = gr.File(label="Job Description")
with gr.Column(scale=0.85):
clear = gr.ClearButton([msg, chatbot])
msg.submit(get_response, [msg, chatbot, resume, jd], [msg, chatbot])
demo.launch(debug =True, share=True)
gradio_interface()