Spaces:
Runtime error
Runtime error
File size: 8,432 Bytes
86c7a3b | 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | from dotenv import load_dotenv
from openai import OpenAI
import json
import os
import requests
from pypdf import PdfReader
import gradio as gr
import glob
import random
import threading
import time
import io
import pathlib
import base64
# Load environment variables from .env file
load_dotenv(override=True)
class AmitKumar:
def __init__(self):
# Initialize the OpenAI client for Gemini API calls
google_api_key = os.getenv("GOOGLE_API_KEY")
self.gemini = OpenAI(api_key=google_api_key, base_url="https://generativelanguage.googleapis.com/v1beta/openai/")
self.model_name = "gemini-2.0-flash"
# Your professional information
self.name = "Amit Kumar"
self.pdf_file = "me/amitcvprofile.pdf" # Updated PDF file name
self.info = """
My name is Amit Kumar. I'm a Senior Test Engineer at HCLTech in Noida. I have extensive experience in manual and automation testing, with **3.5+ years in Selenium with Core Java**, **2+ years in Appium** for mobile automation, and **1+ years in API automation** using Rest Assured and Postman. My overall experience is **4 years and 9 months**.
I am proficient in programming languages, including **Core Java** and **Python**.
My professional expertise also includes **TestNG** and **BDD (Behavior-Driven Development)** with **Gherkin**.
I'm an Agentic AI enthusiast with certifications.
My professional expertise includes building automation frameworks from the ground up, managing CI/CD pipelines with Maven and Jenkins, and handling defect management.
I'm comfortable working across Windows, Mac, and Linux operating systems. I am a native Hindi speaker and am professionally fluent in English.
I love automation, and have hands on automation of web and mobile(android and ios application)
I am currently working in HCLTech with 4+ year of experience.
## Additional Information for Recruiters:
- **Expected Salary:** My expected salary is between 10 to 12 LPA. I prefer not to disclose my current salary.
- **Notice Period:** My notice period is 2 months. I am open to discussing a buyout option if it is available.
"""
def system_prompt(self):
"""
Generates the system prompt to define the chatbot's persona and knowledge base.
"""
prompt = f"""
You are Amit Kumar, a Senior Test Engineer. Your purpose is to answer questions from recruiters about your professional experience.
Your responses must be based solely on the provided information below. Do not make up any details.
Maintain a professional, knowledgeable, and confident tone. Be concise and direct in your answers.
## My Professional Profile:
{self.info}
## Special Instruction:
- If you are asked about messaging on WhatsApp, respond by saying "If you have my number, you can message me there." Do not state that you are an AI or that you cannot be messaged personally.
- If you are asked if my resume is latest on Naukri or for a resume link, respond by saying "Yes, my resume is latest on Naukri, and the link is also available on my LinkedIn profile. If you can't find it, please feel free to email me at amitkumar1508.in@gmail.com."
- If asked about willingness to relocate, say "Yes."
- If asked about willingness to work in a night shift, say "Yes."
Now, a recruiter will ask you questions. Please respond as Amit Kumar based on the provided profile.
If a recruiter asks about something not mentioned in the profile (e.g., personal life, or a specific technology not listed), suggest they email me at amitkumar1508.in@gmail.com for more information. If you are asked to save or note something, say that you will note it down and inform Amit.
"""
return prompt
def chat(self, message, history):
"""
Handles the chat conversation with the model.
The chatbot will use the provided profile to answer questions.
"""
# Create the message history for the Gemini API call
gemini_messages = [{"role": "system", "content": self.system_prompt()}]
for user_msg, bot_msg in history:
# Append user messages to the history
gemini_messages.append({"role": "user", "content": user_msg})
# Append bot messages to the history
if bot_msg:
gemini_messages.append({"role": "assistant", "content": bot_msg})
# Add the new user message to the conversation history before making the API call
gemini_messages.append({"role": "user", "content": message})
# Make the API call to Gemini
response = self.gemini.chat.completions.create(
model=self.model_name,
messages=gemini_messages
)
# Extract the content from the response
return response.choices[0].message.content
# Placeholder for a push notification function
def push(text):
"""
Sends a push notification using the Pushover API.
(Placeholder function, as environment variables are not available here)
"""
pushover_token = os.getenv("PUSHOVER_TOKEN")
pushover_user = os.getenv("PUSHOVER_USER")
if pushover_token and pushover_user:
requests.post(
"https://api.pushover.net/1/messages.json",
data={
"token": pushover_token,
"user": pushover_user,
"message": text,
}
)
else:
print(f"Push notification sent: {text}")
# Create an instance of the AmitKumar class in the global scope
# so it can be accessed by the get_agent_response function.
amit = AmitKumar()
# Gradio interface setup
def get_agent_response(message, history):
"""
A wrapper function to get the chatbot's response for Gradio.
"""
# Send push notification for the user's message
push(f"User message received: {message}")
# Create an empty response for the user's message
history.append((message, None))
# Yield the updated history so the user's message appears immediately
yield "", history
# Get the model's response
response = amit.chat(message, history)
# Update the last message with the model's response
history[-1] = (message, response)
# Send push notification for the agent's reply
push(f"Agent replied: {response}")
# Yield the final history
yield "", history
if __name__ == "__main__":
# Define a helper function to copy text to clipboard
js_copy_email = """
function(text) {
navigator.clipboard.writeText(text);
return 'Email copied to clipboard!';
}
"""
with gr.Blocks() as demo:
# Chatbot header, now at the top of the full page
with gr.Row():
with gr.Column(elem_id="contact-info"):
# Use HTML to make the name larger and bolder
gr.HTML("<h1 style='text-align:center;'><b>Amit Kumar</b></h1>")
gr.Markdown("<center>Senior Test Engineer, HCLTech, Noida, Email: amitkumar1508.in@gmail.com</center>")
gr.Button("View LinkedIn Profile", link="https://www.linkedin.com/in/amit-kumar-1508g/")
# Main content, centered
with gr.Column():
with gr.Column():
chatbot = gr.Chatbot(label="Chat with Amit", height=500)
with gr.Row(equal_height=True):
msg = gr.Textbox(
placeholder="Ask me anything about my experience and skills...",
show_label=False,
scale=1
)
submit_btn = gr.Button("Ask", scale=0)
msg.submit(
fn=get_agent_response,
inputs=[msg, chatbot],
outputs=[msg, chatbot],
api_name="chat"
)
submit_btn.click(
fn=get_agent_response,
inputs=[msg, chatbot],
outputs=[msg, chatbot],
api_name="chat"
)
demo.launch()
|