Voice-Bot-AI / app.py
Krishnavamshithumma's picture
Update app.py
0e1ca59 verified
raw
history blame
3.84 kB
import gradio as gr
from openai import OpenAI
system_prompt = """
You are a voice bot representing Krishnavamshi Thumma. When responding to questions, answer as if you are:
- A Generative AI and Data Engineering enthusiast with 1.5+ years of experience in data pipelines, automation, and scalable solutions
- Currently working as a Data Engineer at Wishkarma in Hyderabad, where you've optimized ETL pipelines processing 10K+ records daily and developed an image-based product similarity search engine using CLIP-ViT-L/14
- Previously worked as a Data Engineer Intern at DeepThought Growth Management System, where you processed 700+ data records and mentored 400+ students
- Skilled in Python, SQL, JavaScript (Node.js), OpenAI GPT-4o, LangChain, MongoDB Vector Search, FAISS, Apache Airflow, AWS Lambda, and FastAPI
- Experienced in building GenAI products including conversational AI chatbots, RAG pipelines, and AI-powered tools
- A Computer Science graduate from Neil Gogte Institute of Technology with a CGPA of 7.5/10
- Passionate about solving real-world problems at the intersection of AI and software engineering
Answer questions about your background, experience, projects, and skills based on this resume. Keep responses professional but engaging (2-3 sentences max for most questions).
"""
def chat_with_openai(user_input, history, api_key):
if not api_key:
return history, "❌ Please enter your OpenAI API key."
try:
client = OpenAI(api_key=api_key)
# Build messages from history
messages = [{"role": "system", "content": system_prompt}]
for entry in history:
messages.append({"role": "user", "content": entry[0]})
messages.append({"role": "assistant", "content": entry[1]})
messages.append({"role": "user", "content": user_input})
# Get response from OpenAI
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
temperature=0.7
)
bot_reply = response.choices[0].message.content
history.append((user_input, bot_reply))
return history, history
except Exception as e:
return history, f"❌ Error: {str(e)}"
with gr.Blocks(title="Voice Bot: Krishnavamshi Thumma", js="./custom.js") as demo:
gr.Markdown("## πŸŽ™οΈ Krishnavamshi Thumma - Voice Assistant")
# Add custom CSS
gr.HTML("""
<style>
#chatBox {
height: 60vh;
overflow-y: auto;
padding: 20px;
border-radius: 10px;
background: #f9f9f9;
}
.message {
margin: 10px 0;
padding: 12px;
border-radius: 8px;
}
.user {
background: #e3f2fd;
text-align: right;
}
.bot {
background: #f5f5f5;
}
#micButton {
width: 100%;
padding: 12px;
font-size: 1.2em;
}
</style>
""")
api_key = gr.Textbox(label="πŸ” OpenAI API Key", type="password", elem_id="apiKeyInput")
chatbot = gr.Chatbot(elem_id="chatBox", type="messages")
state = gr.State([])
with gr.Row():
mic_btn = gr.Button("🎀 Speak", elem_id="micButton")
clear_btn = gr.Button("πŸ—‘οΈ Clear Chat")
# Hidden components for JS communication
voice_input = gr.Textbox(visible=False, elem_id="voiceInput")
# Event handlers
voice_input.change(
chat_with_openai,
[voice_input, state, api_key],
[chatbot, state]
)
# Corrected JS trigger syntax
mic_btn.click(None, [], [], js="startListening")
clear_btn.click(lambda: ([], []), None, [chatbot, state])
demo.launch()