File size: 3,837 Bytes
b2ef4a4
 
 
 
c53823f
b2ef4a4
c53823f
 
 
 
 
 
 
b2ef4a4
c53823f
 
b2ef4a4
c53823f
b2ef4a4
5ef46b2
c53823f
b2ef4a4
 
5ef46b2
c53823f
5ef46b2
c53823f
 
 
 
5ef46b2
c53823f
 
 
5ef46b2
 
b2ef4a4
c53823f
 
 
5ef46b2
c53823f
b2ef4a4
c53823f
b2ef4a4
c53823f
 
 
0e1ca59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c53823f
0e1ca59
c53823f
 
 
 
 
 
 
 
 
 
 
 
 
 
5ef46b2
0e1ca59
 
 
c53823f
5ef46b2
c53823f
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
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()