File size: 4,926 Bytes
a8e5626
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Rakesh Kumar Portfolio Chatbot
Gradio app with Groq LLM integration and session management
"""
import os
import uuid
import time
import gradio as gr
from groq import Groq

# Session management with 1-hour TTL
sessions = {}
SESSION_TTL = 3600  # 1 hour in seconds

def cleanup_expired_sessions():
    """Remove sessions older than TTL"""
    current_time = time.time()
    expired = [sid for sid, data in sessions.items() if current_time - data['created_at'] > SESSION_TTL]
    for sid in expired:
        del sessions[sid]

def get_or_create_session(session_id: str) -> list:
    """Get existing session or create new one"""
    cleanup_expired_sessions()
    
    if session_id not in sessions:
        sessions[session_id] = {
            'history': [],
            'created_at': time.time()
        }
    return sessions[session_id]['history']

# System prompt with Rakesh's background
SYSTEM_PROMPT = """You are a helpful AI assistant representing Rakesh Kumar's portfolio. Answer questions about Rakesh's experience, skills, projects, and background.

## About Rakesh Kumar
- **Current Role**: AI Product Manager & AI Lead at Dr. Reddy's (Svaas Wellness) since Feb 2023
- **Experience**: 7+ years in AI, healthcare, and e-commerce
- **Education**: MBA from IIM Ahmedabad (2018-2020), B.Tech from IIT Ropar (2011-2015)
- **Location**: India
- **Contact**: p18rakeshk@iima.ac.in | +91-9004260456

## Key Projects

### AI Playground
Low-code platform for business owners to create prototype AI agents. Features RAG pipeline creation, evaluation frameworks, orchestration layer, database integration hooks, and configuration layer for validating model responses.

### Medical Deep Research Agent
Secondary research tool for pharma teams covering epidemiology, clinical trials, pharmacokinetics, safety, unmet needs. Built with RAG + Knowledge Graph, multi-agent architecture using SLMs and TinyLLM for knowledge extraction.

### SemaAI Agent
Fully on-premise enterprise chatbot using TinyLLM, LoRA fine-tuning, RAG-grounded responses, and custom MLP layer for intent classification.

### Recommendation Engine (eShakti)
Hybrid recommendation system using User-User, Item-Item, User-Item collaborative filtering with SVD, dimensionality reduction, and neural networks. Achieved +$50k/month revenue, +7% conversion.

## Key Achievements
- 70%+ manual tasks reduced using agentic AI workflows
- 80% faster insight generation with BI dashboards
- 10× clinical research turnaround acceleration
- 85% ML + LLM diet engine accuracy
- 20k+ users onboarded in 90 days

## Skills
Product Strategy, Roadmapping, AI/ML, LLM & RAG, GenAI Voice, Experimentation, SQL, Python, Data Platforms, Health Tech, E-commerce

## Certifications
IBM AI Product Manager, IBM AI Developer, Google Digital Marketing, Six Sigma Green Belt

Be concise, professional, and helpful. If asked something not about Rakesh, politely redirect to portfolio-related topics."""

# Initialize Groq client
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

def chat(message: str, history: list, request: gr.Request) -> str:
    """Process chat message with Groq LLM"""
    
    # Get session ID from cookies or create new one
    session_id = str(uuid.uuid4()) if not hasattr(request, 'session_hash') else request.session_hash
    
    # Get session history
    session_history = get_or_create_session(session_id)
    
    # Build messages for Groq
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]
    
    # Add session history
    for h in session_history:
        messages.append({"role": "user", "content": h[0]})
        messages.append({"role": "assistant", "content": h[1]})
    
    # Add current message
    messages.append({"role": "user", "content": message})
    
    try:
        # Call Groq API
        completion = client.chat.completions.create(
            model="llama-3.3-70b-versatile",
            messages=messages,
            temperature=0.7,
            max_tokens=1024,
        )
        
        response = completion.choices[0].message.content
        
        # Update session history
        session_history.append((message, response))
        
        return response
        
    except Exception as e:
        return f"I apologize, but I encountered an error. Please try again. Error: {str(e)}"

# Create Gradio interface
with gr.Blocks(
    title="Chat with Rakesh's Portfolio",
) as demo:
    gr.Markdown("""
    # 💬 Ask About Rakesh Kumar
    *AI Product Manager & AI Lead*
    
    Ask me anything about Rakesh's experience, projects, skills, or background!
    """)
    
    chatbot = gr.ChatInterface(
        fn=chat,
        examples=[
            "What is Rakesh's current role?",
            "Tell me about the AI Playground project",
            "What are Rakesh's key achievements?",
            "What is his educational background?",
        ],
    )

if __name__ == "__main__":
    demo.launch()