Spaces:
Sleeping
Sleeping
File size: 18,086 Bytes
a87f605 77ba684 a87f605 3d5262b 46e172a 3d5262b |
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
---
title: Yashgori
emoji: π
colorFrom: blue
colorTo: gray
sdk: docker
sdk_version: "0.0.1"
app_file: app.py
pinned: false
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# π€ Yash Gori AI Portfolio API v2.0 - Complete Implementation Guide
## **Overview**
This is a sophisticated AI portfolio chatbot that intelligently adapts to different types of visitors (recruiters, developers, students, etc.) and provides personalized responses about Yash Gori's skills, projects, and qualifications.
---
## **π― Complete Features Implemented (A to Z)**
### **Core AI Intelligence**
- β
**Intelligent AI Agent** with personality using Groq Llama 3.3 70B
- β
**User Intent Detection** (recruiter/technical/collaborator/student/general)
- β
**Sophistication Level Analysis** (beginner/intermediate/advanced)
- β
**Dynamic Response Adaptation** based on user type and context
- β
**Natural Language Processing** with context understanding
### **Conversation Management**
- β
**Session Management** with UUID-based session IDs
- β
**Conversation Memory** building context over multiple exchanges
- β
**Topic Tracking** and theme analysis
- β
**Question Clarity Detection** with clarifying question generation
- β
**Follow-up Engagement** prompts to continue conversations
### **Smart Features**
- β
**Smart Suggestions** based on conversation flow patterns
- β
**Rich Content Integration** with contextual project details
- β
**Project Mention Detection** with GitHub links
- β
**Contextual Information** delivery based on questions
- β
**Intelligent Fallback Responses** when AI unavailable
### **Rate Limiting & Security**
- β
**Multi-level Rate Limiting** (IP-based: 60/hour, Session-based: 20/hour)
- β
**Background Session Cleanup** every 10 minutes
- β
**Rate Limit Headers** in responses
- β
**IP Address Tracking** (partially masked for privacy)
### **Database & Analytics**
- β
**SQLite Database** with visitor tracking
- β
**User Profile Storage** with conversation history
- β
**Real-time Analytics** collection
- β
**Daily Analytics Summaries** with trends
- β
**Comprehensive Dashboard** with insights
- β
**Data Export** capabilities for analysis
### **API Structure**
- β
**RESTful API Design** with proper HTTP methods
- β
**Enhanced JSON Responses** with metadata
- β
**Error Handling** with fallback responses
- β
**CORS Support** for frontend integration
- β
**Database Migration** system for schema updates
---
## **π Complete Workflow**
### **1. User Interaction Flow**
```
User Visits β Session Created β Question Asked β AI Processing β Response Generation β Analytics Saved β Smart Suggestions Provided
```
### **2. Behind-the-Scenes Process**
```
1. Session Management:
- Generate/retrieve session ID
- Check rate limits (IP + Session)
- Load conversation memory
2. User Analysis:
- Detect user intent (recruiter/technical/etc.)
- Analyze sophistication level
- Check question clarity
3. Context Building:
- Retrieve conversation history
- Build context summary
- Detect mentioned projects
4. AI Response Generation:
- Create intelligent agent prompt
- Call Groq API with context
- Process and validate response
5. Intelligence Layer:
- Generate smart suggestions
- Extract rich content
- Analyze conversation flow
6. Data Persistence:
- Save conversation to database
- Update user profile
- Update daily analytics
7. Response Assembly:
- Build comprehensive JSON response
- Include metadata and suggestions
- Apply rate limit headers
```
---
## **π Complete API Routes**
### **1. Main Chat Endpoint**
```http
POST /ask
```
**Request:**
```json
{
"question": "What are Yash's technical skills?",
"session_id": "optional-uuid-here"
}
```
**Response:**
```json
{
"success": true,
"api_version": "2.0",
"session": {
"session_id": "1e9704c6-eecb-4d32-9066-d8d62c9d9682",
"conversation_number": 3,
"user_status": "returning",
"session_created": "2025-08-10T21:00:00"
},
"request": {
"question": "What are Yash's technical skills?",
"processed_at": "2025-08-10T21:18:00",
"response_time_ms": null
},
"response": {
"answer": "Yash has strong technical skills in AI/ML, Python, Flask, RAG systems...",
"model_used": "openai/gpt-oss-120b",
"confidence_indicators": {
"question_clarity": 0.9,
"user_type_confidence": 0.8,
"response_relevance": 0.9
}
},
"intelligence": {
"user_analysis": {
"detected_type": "technical",
"sophistication_level": "intermediate",
"question_clarity": "Clear technical inquiry",
"is_returning_user": true,
"previous_topics": ["skills", "projects"]
},
"conversation_state": {
"total_exchanges": 3,
"main_themes": ["technical_skills", "ai_projects"],
"user_progression": ["exploring", "deepening"],
"conversation_depth": "moderate"
},
"smart_suggestions": {
"follow_up_questions": [
"Would you like to see specific examples of his AI projects?",
"How do his skills align with your team's needs?"
],
"topic_transitions": [
"Let's dive deeper into the area that interests you most"
],
"depth_exploration": [
"Want to discuss the system architecture in detail?"
]
}
},
"rich_content": {
"DocuTalk": {
"github_link": "https://github.com/yashnileshgori/DocuTalk",
"technical_specs": ["RAG", "LangChain", "Streamlit"],
"key_achievement": "Conversational document AI"
}
},
"metadata": {
"rate_limit": {
"requests_remaining": 58,
"window_reset": "2025-08-10T22:18:00"
},
"developer": "Yash Gori",
"timestamp": "2025-08-10T21:18:00"
}
}
```
### **2. API Information**
```http
GET /
```
**Response:**
```json
{
"message": "Welcome to Yash Gori's AI Portfolio API",
"version": "2.0",
"developer": "Yash Gori",
"description": "Intelligent portfolio chatbot with adaptive responses",
"endpoints": {
"POST /ask": "Main chat endpoint",
"GET /profile": "Complete profile data",
"GET /analytics/dashboard": "Analytics dashboard"
}
}
```
### **3. Complete Profile**
```http
GET /profile
```
**Response:**
```json
{
"success": true,
"developer": "Yash Gori",
"profile": {
"personal_info": {
"name": "Yash Gori",
"email": "[email protected]",
"phone": "+91-XXXXXXXXXX"
},
"current_position": {
"role": "AI Engineer Intern",
"company": "Webotix IT Consultancy"
},
"education": {
"current": {
"degree": "BTech in Information Technology",
"college": "KJ Somaiya College of Engineering",
"cgpa": "8.12"
}
}
}
}
```
### **4. Session State**
```http
GET /session/{session_id}/state
```
**Response:**
```json
{
"success": true,
"session_id": "uuid-here",
"session_exists": true,
"profile": {
"primary_type": "technical",
"sophistication_level": "intermediate",
"conversation_count": 5
},
"conversation_memory": {
"total_exchanges": 5,
"main_themes": ["skills", "projects"],
"conversation_depth": "deep"
}
}
```
### **5. Session History**
```http
GET /session/{session_id}/history
```
**Response:**
```json
{
"success": true,
"session_id": "uuid-here",
"total_conversations": 5,
"conversation_history": [
{
"turn": 1,
"timestamp": "2025-08-10T21:00:00",
"question": "What are Yash's skills?",
"answer": "Yash has strong technical skills...",
"user_type": "technical",
"sophistication": "intermediate"
}
]
}
```
### **6. Analytics Dashboard**
```http
GET /analytics/dashboard
```
**Response:**
```json
{
"success": true,
"dashboard_title": "Yash Gori's AI Portfolio Analytics Dashboard",
"generated_at": "2025-08-10T21:18:00",
"overview": {
"total_conversations": 150,
"unique_visitors": 45,
"avg_question_length": 25.5,
"avg_answer_length": 180.2
},
"user_types": {
"recruiter": 30,
"technical": 45,
"general": 75
},
"engagement_metrics": {
"avg_conversations_per_session": 2.3,
"multi_turn_sessions": 20,
"highly_engaged_sessions": 8
},
"summary_insights": {
"engagement_rate": 3.33,
"top_user_type": "technical",
"peak_activity_hour": "14"
}
}
```
### **7. Session Analytics**
```http
GET /analytics/session/{session_id}
```
**Response:**
```json
{
"success": true,
"session_id": "uuid-here",
"conversation_count": 5,
"user_journey": [
{
"turn": 1,
"question": "What are Yash's skills?",
"detected_type": "technical",
"sophistication": "intermediate"
}
],
"topics_explored": ["DocuTalk", "Finance Advisor"],
"detected_user_types": ["technical", "recruiter"]
}
```
### **8. Daily Analytics**
```http
GET /analytics/daily
```
**Response:**
```json
{
"success": true,
"daily_analytics": [
{
"date": "2025-08-10",
"total_conversations": 25,
"unique_sessions": 12,
"user_type_breakdown": {"technical": 10, "recruiter": 8},
"avg_conversation_length": 150
}
],
"trends": {
"conversation_trend": 5,
"session_trend": 2
}
}
```
### **9. Export Analytics**
```http
GET /analytics/export
```
**Response:**
```json
{
"success": true,
"export_metadata": {
"generated_at": "2025-08-10T21:18:00",
"total_records": 150,
"analytics_version": "2.0"
},
"full_analytics": { /* Complete analytics data */ },
"conversation_records": [ /* All conversations */ ]
}
```
### **10. Admin Conversations**
```http
GET /admin/conversations
```
**Response:**
```json
{
"success": true,
"total_conversations": 150,
"conversations": [
{
"id": "uuid",
"session_id": "session-uuid",
"timestamp": "2025-08-10T21:00:00",
"user_type": "technical",
"question": "What are Yash's skills?",
"answer": "Yash has strong technical skills..."
}
]
}
```
### **11. Admin Profiles**
```http
GET /admin/profiles
```
**Response:**
```json
{
"success": true,
"total_unique_visitors": 45,
"profiles": [
{
"session_id": "uuid",
"primary_type": "technical",
"conversation_count": 5,
"first_seen": "2025-08-10T20:00:00",
"last_seen": "2025-08-10T21:00:00"
}
],
"analytics": {
"user_types": {"technical": 20, "recruiter": 15},
"skill_levels": {"intermediate": 25, "advanced": 10}
}
}
```
---
## **π₯ Frontend Integration Guide**
### **1. Essential Frontend Components**
#### **Chat Interface**
```javascript
class YashChatbot {
constructor() {
this.sessionId = localStorage.getItem('yashChatSession') || null;
this.apiBase = 'YOUR_API_URL';
}
async sendMessage(question) {
const payload = {
question: question,
session_id: this.sessionId
};
const response = await fetch(`${this.apiBase}/ask`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await response.json();
// Store session ID for continuity
if (!this.sessionId && data.session?.session_id) {
this.sessionId = data.session.session_id;
localStorage.setItem('yashChatSession', this.sessionId);
}
return data;
}
}
```
#### **Message Display**
```javascript
function displayMessage(data) {
// Main response
addMessage(data.response.answer, 'bot');
// Smart suggestions as quick reply buttons
if (data.intelligence?.smart_suggestions?.follow_up_questions) {
showQuickReplies(data.intelligence.smart_suggestions.follow_up_questions);
}
// Rich content for projects
if (data.rich_content) {
displayProjectCards(data.rich_content);
}
// User type indicator (optional)
if (data.intelligence?.user_analysis?.detected_type !== 'general') {
showUserTypeIndicator(data.intelligence.user_analysis.detected_type);
}
}
```
### **2. Required Frontend Features**
#### **Session Management**
- Store `session_id` in localStorage
- Include in all subsequent requests
- Handle session restoration
#### **Rate Limit Handling**
```javascript
function handleRateLimit(data) {
if (data.metadata?.rate_limit?.requests_remaining < 5) {
showWarning(`${data.metadata.rate_limit.requests_remaining} requests remaining`);
}
}
```
#### **Smart Suggestions**
```javascript
function showQuickReplies(suggestions) {
const container = document.getElementById('quick-replies');
container.innerHTML = '';
suggestions.forEach(suggestion => {
const button = document.createElement('button');
button.textContent = suggestion;
button.onclick = () => sendMessage(suggestion);
container.appendChild(button);
});
}
```
#### **Rich Content Display**
```javascript
function displayProjectCards(richContent) {
Object.entries(richContent).forEach(([projectName, details]) => {
const card = createProjectCard({
name: projectName,
github: details.github_link,
specs: details.technical_specs,
achievement: details.key_achievement
});
document.getElementById('rich-content').appendChild(card);
});
}
```
### **3. Error Handling**
```javascript
async function handleApiCall(question) {
try {
const data = await chatbot.sendMessage(question);
if (data.success) {
displayMessage(data);
handleRateLimit(data);
} else {
// Show fallback response
if (data.fallback_answer) {
addMessage(data.fallback_answer, 'bot');
}
}
} catch (error) {
addMessage("Sorry, I'm having trouble connecting. Please try again.", 'bot');
}
}
```
### **4. Analytics Integration (Optional)**
```javascript
// For admin dashboard
async function loadAnalytics() {
const response = await fetch(`${apiBase}/analytics/dashboard`);
const analytics = await response.json();
displayAnalyticsDashboard(analytics);
}
// For session insights
async function showSessionInsights(sessionId) {
const response = await fetch(`${apiBase}/analytics/session/${sessionId}`);
const insights = await response.json();
displaySessionJourney(insights.user_journey);
}
```
---
## **π§ Technical Implementation Notes**
### **Database Schema**
```sql
-- Main conversations table
CREATE TABLE visitors (
id TEXT PRIMARY KEY,
session_id TEXT,
timestamp TEXT,
user_type TEXT,
question TEXT,
answer TEXT,
user_info TEXT,
ip_address TEXT
);
-- User profiles table
CREATE TABLE user_profiles (
session_id TEXT PRIMARY KEY,
primary_type TEXT,
sophistication_level TEXT,
interests TEXT,
conversation_count INTEGER,
first_seen TEXT,
last_seen TEXT,
profile_data TEXT
);
-- Daily analytics table
CREATE TABLE daily_analytics (
date TEXT PRIMARY KEY,
total_conversations INTEGER,
unique_sessions INTEGER,
user_type_breakdown TEXT,
avg_conversation_length INTEGER,
top_questions TEXT,
updated_at TIMESTAMP
);
```
### **Key Configuration**
```python
# API Configuration
GROQ_API_KEY = "your-groq-api-key"
DB_PATH = "/tmp/visitors.db"
# Rate Limits
IP_RATE_LIMIT = 60 # per hour
SESSION_RATE_LIMIT = 20 # per hour
# Session Configuration
SESSION_TIMEOUT = 1800 # 30 minutes
CLEANUP_INTERVAL = 600 # 10 minutes
```
### **Environment Variables**
```bash
GROQ_API_KEY=your_groq_api_key_here
PORT=7860
SQLITE_DB_PATH=/tmp/visitors.db
```
---
## **π Deployment Checklist**
### **Backend (Flask API)**
- β
Valid Groq API key configured
- β
Database migrations applied
- β
CORS configured for frontend domain
- β
Rate limiting active
- β
Background cleanup running
- β
Analytics collection enabled
### **Frontend Integration**
- β
API endpoint configured correctly
- β
Session management implemented
- β
Error handling for API failures
- β
Smart suggestions display
- β
Rich content rendering
- β
Rate limit handling
### **Testing**
- β
Test different user types (recruiter/technical/general)
- β
Verify conversation memory works
- β
Check smart suggestions appear
- β
Confirm analytics are collected
- β
Test rate limiting behavior
- β
Verify session continuity
---
## **π Success Metrics**
The API provides detailed metrics to measure success:
- **Engagement Rate**: Conversations per unique visitor
- **User Type Distribution**: Which types of users visit most
- **Conversation Depth**: How many exchanges per session
- **Popular Topics**: Most asked questions
- **Peak Activity**: Best times for engagement
- **Return Visitors**: Session continuity tracking
---
**This comprehensive AI portfolio chatbot transforms basic interactions into intelligent, personalized conversations that adapt to each visitor's needs while providing deep insights into user engagement patterns.** |