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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
#!/usr/bin/env python3
"""
๐ŸŽฏ EKALAVYA - The Ultimate AI Teaching Assistant
๐ŸŒŸ Multi-Modal โ€ข Multi-Lingual โ€ข Memory-Powered
๐Ÿ›ก๏ธ Safe โ€ข ๐ŸŽ“ Educational โ€ข ๐Ÿ’ Friendly
"""

from fastapi import FastAPI, HTTPException, UploadFile, File, Form
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
from typing import Optional, List, Dict
import json
import os

# Import all modules
from model.teaching import TeachingMode
from model.safety import SafetyRules
from model.memory import MemorySystem

# ๐ŸŽฏ Initialize FastAPI with style
app = FastAPI(
    title="๐ŸŽฏ EKALAVYA API",
    description="๐ŸŒŸ The Ultimate AI Teaching Assistant - Multi-Modal, Multi-Lingual, Memory-Powered",
    version="3.0.0",
    docs_url="/docs",
    redoc_url="/redoc"
)

# ๐Ÿ›ก๏ธ Initialize safety rules
safety = SafetyRules()

# ๐ŸŽฏ Initialize teaching mode
teaching_mode = TeachingMode(style="friend")

# ๐Ÿ“ Data directory
DATA_DIR = "data"
os.makedirs(DATA_DIR, exist_ok=True)


# ๐Ÿ“ฆ Request/Response Models
class TeachingRequest(BaseModel):
    """๐Ÿ“š Teaching request model"""
    input_text: str
    user_id: str = "default_user"
    conversation_style: str = "friend"  # friend, teacher, lover, mentor
    language: str = "english"


class SafetyCheckRequest(BaseModel):
    """๐Ÿ›ก๏ธ Safety check request model"""
    content: str
    check_type: str = "all"  # all, scam, hacking, privacy, inappropriate


class ProgressRequest(BaseModel):
    """๐Ÿ“Š Progress request model"""
    user_id: str


class StyleRequest(BaseModel):
    """๐Ÿ’ Conversation style request model"""
    style: str  # friend, teacher, lover, mentor
    user_id: str = "default_user"


# ๐Ÿ  Root endpoint
@app.get("/", response_class=HTMLResponse)
async def root():
    """๐ŸŽฏ Welcome page with emojis"""
    return """
    <!DOCTYPE html>
    <html>
    <head>
        <title>๐ŸŽฏ EKALAVYA - AI Teaching Assistant</title>
        <style>
            body { 
                font-family: Arial, sans-serif; 
                max-width: 800px; 
                margin: 50px auto; 
                padding: 20px;
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                color: white;
            }
            .card {
                background: rgba(255,255,255,0.95);
                color: #333;
                padding: 30px;
                border-radius: 20px;
                box-shadow: 0 10px 40px rgba(0,0,0,0.3);
                margin: 20px 0;
            }
            h1 { font-size: 3em; text-align: center; }
            .emoji { font-size: 1.5em; }
            .feature { 
                background: #f0f0f0; 
                padding: 15px; 
                margin: 10px 0; 
                border-radius: 10px;
                border-left: 5px solid #667eea;
            }
            .stats { 
                display: flex; 
                justify-content: space-around; 
                margin: 30px 0;
            }
            .stat {
                text-align: center;
                padding: 20px;
                background: rgba(255,255,255,0.1);
                border-radius: 15px;
                flex: 1;
                margin: 0 10px;
            }
            .stat-number { font-size: 2.5em; font-weight: bold; }
            a { color: #667eea; text-decoration: none; font-weight: bold; }
            a:hover { text-decoration: underline; }
        </style>
    </head>
    <body>
        <div class="card">
            <h1>๐ŸŽฏ EKALAVYA</h1>
            <p style="text-align: center; font-size: 1.3em;">
                ๐ŸŒŸ The Ultimate AI Teaching Assistant ๐ŸŒŸ
            </p>
            
            <div class="stats">
                <div class="stat">
                    <div class="stat-number">๐ŸŒ 23</div>
                    <div>Indian Languages</div>
                </div>
                <div class="stat">
                    <div class="stat-number">๐Ÿง  1M</div>
                    <div>Token Context</div>
                </div>
                <div class="stat">
                    <div class="stat-number">๐Ÿ›ก๏ธ 100%</div>
                    <div>Safe & Private</div>
                </div>
            </div>

            <h2>โœจ Features</h2>
            
            <div class="feature">
                <span class="emoji">๐ŸŽ“</span> <strong>Teaching Mode</strong>
                <p>Learn English with real-time mistake detection and correction</p>
            </div>
            
            <div class="feature">
                <span class="emoji">๐Ÿง </span> <strong>Memory System</strong>
                <p>Remembers your mistakes and tracks your learning progress</p>
            </div>
            
            <div class="feature">
                <span class="emoji">๐Ÿ’</span> <strong>Conversation Styles</strong>
                <p>Choose: Friend ๐Ÿ‘ซ, Teacher ๐Ÿ‘จโ€๐Ÿซ, Lover ๐Ÿ’•, or Mentor ๐ŸŽ“</p>
            </div>
            
            <div class="feature">
                <span class="emoji">๐Ÿ›ก๏ธ</span> <strong>Safety First</strong>
                <p>Scam detection, hacking prevention, privacy protection</p>
            </div>
            
            <div class="feature">
                <span class="emoji">๐ŸŒ</span> <strong>Multi-Modal</strong>
                <p>Supports text, images, video, and audio</p>
            </div>
            
            <div class="feature">
                <span class="emoji">๐Ÿ”’</span> <strong>100% Private</strong>
                <p>All data stays on your device, no tracking</p>
            </div>

            <h2>๐Ÿ“š API Endpoints</h2>
            
            <div class="feature">
                <strong>POST /teach</strong> - Start learning session
            </div>
            
            <div class="feature">
                <strong>POST /safety/check</strong> - Check content safety
            </div>
            
            <div class="feature">
                <strong>GET /safety/tips</strong> - Get safety tips
            </div>
            
            <div class="feature">
                <strong>POST /progress</strong> - View learning progress
            </div>
            
            <div class="feature">
                <strong>POST /style</strong> - Change conversation style
            </div>

            <h2>๐Ÿ”— Quick Links</h2>
            <p>
                ๐Ÿ“– <a href="/docs">Interactive API Docs</a> |
                ๐Ÿ“Š <a href="/redoc">Alternative Docs</a> |
                ๐ŸŽฏ <a href="https://huggingface.co/hackerbhai/vinaymodel">HuggingFace Model</a>
            </p>

            <p style="text-align: center; margin-top: 30px; font-size: 1.2em;">
                ๐ŸŽฏ Built with โค๏ธ for learners everywhere ๐ŸŒ
            </p>
        </div>
    </body>
    </html>
    """


# ๐ŸŽ“ Teaching endpoint
@app.post("/teach")
async def teach(request: TeachingRequest):
    """๐ŸŽ“ Start teaching session with mistake detection"""
    try:
        # ๐Ÿ›ก๏ธ Safety check first
        safety_check = safety.check_content(request.input_text)
        if not safety_check['is_safe']:
            return {
                "status": "๐Ÿ›ก๏ธ safety_warning",
                "message": safety_check['warnings'][0],
                "suggestions": safety_check['suggestions']
            }
        
        # ๐ŸŽฏ Process teaching request
        result = teaching_mode.process_teaching_request(
            user_input=request.input_text,
            user_id=request.user_id,
            conversation_style=request.conversation_style,
            language=request.language
        )
        
        return {
            "status": "โœ… success",
            "response": result['response'],
            "mistakes_found": result['mistakes'],
            "corrections": result['corrections'],
            "explanation": result['explanation'],
            "encouragement": result['encouragement'],
            "next_steps": result['next_steps'],
            "emoji": "๐ŸŽ‰" if result['mistakes'] else "โœจ"
        }
        
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")


# ๐Ÿ›ก๏ธ Safety check endpoint
@app.post("/safety/check")
async def check_safety(request: SafetyCheckRequest):
    """๐Ÿ›ก๏ธ Check if content is safe"""
    result = safety.check_content(request.content)
    
    return {
        "is_safe": result['is_safe'],
        "violations": result['violations'],
        "warnings": result['warnings'],
        "suggestions": result['suggestions'],
        "emoji": "โœ…" if result['is_safe'] else "โš ๏ธ",
        "message": "โœ… Content is safe!" if result['is_safe'] else "โš ๏ธ Safety issues detected"
    }


# ๐Ÿ’ก Safety tips endpoint
@app.get("/safety/tips")
async def get_safety_tips():
    """๐Ÿ’ก Get safety tips with emojis"""
    tips = safety.get_safety_tips()
    
    emoji_tips = [
        f"๐Ÿ”’ {tips['privacy_protection'][0]}",
        f"๐Ÿ›ก๏ธ {tips['privacy_protection'][1]}",
        f"๐Ÿšซ {tips['prohibited_actions'][0]}",
        f"โš ๏ธ {tips['prohibited_actions'][1]}",
        f"๐Ÿ’ {tips['positive_behaviors'][0]}",
        f"๐ŸŒŸ {tips['positive_behaviors'][1]}",
    ]
    
    return {
        "tips": emoji_tips,
        "count": len(emoji_tips),
        "emoji": "๐Ÿ’ก",
        "message": "๐Ÿ’ก Stay safe with these tips!"
    }


# ๐Ÿ“Š Progress endpoint
@app.post("/progress")
async def get_progress(request: ProgressRequest):
    """๐Ÿ“Š Get user learning progress"""
    memory = MemorySystem(user_id=request.user_id)
    stats = memory.get_user_stats()
    
    # Calculate learning score
    total_attempts = stats['total_attempts']
    correct_attempts = stats['correct_attempts']
    learning_score = (correct_attempts / total_attempts * 100) if total_attempts > 0 else 0
    
    return {
        "user_id": request.user_id,
        "stats": stats,
        "learning_score": round(learning_score, 2),
        "emoji": "๐Ÿ†" if learning_score > 80 else "๐Ÿ“ˆ" if learning_score > 50 else "๐Ÿ’ช",
        "message": "๐Ÿ† Excellent progress!" if learning_score > 80 else 
                   "๐Ÿ“ˆ Good progress, keep going!" if learning_score > 50 else 
                   "๐Ÿ’ช Keep practicing, you'll improve!"
    }


# ๐Ÿ’ Style change endpoint
@app.post("/style")
async def change_style(request: StyleRequest):
    """๐Ÿ’ Change conversation style"""
    styles = {
        "friend": "๐Ÿ‘ซ",
        "teacher": "๐Ÿ‘จโ€๐Ÿซ",
        "lover": "๐Ÿ’•",
        "mentor": "๐ŸŽ“"
    }
    
    if request.style not in styles:
        raise HTTPException(
            status_code=400, 
            detail=f"โŒ Invalid style. Choose from: {', '.join(styles.keys())}"
        )
    
    teaching_mode.set_style(request.style, request.user_id)
    
    return {
        "status": "โœ… success",
        "style": request.style,
        "emoji": styles[request.style],
        "message": f"{styles[request.style]} Now talking as your {request.style}!"
    }


# ๐ŸŒ Languages endpoint
@app.get("/languages")
async def get_languages():
    """๐ŸŒ Get supported languages with flags"""
    languages = {
        "english": {"name": "English", "flag": "๐Ÿ‡ฌ๐Ÿ‡ง", "emoji": "๐Ÿ“š"},
        "hindi": {"name": "Hindi", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“–"},
        "bengali": {"name": "Bengali", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“"},
        "telugu": {"name": "Telugu", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "โœ๏ธ"},
        "tamil": {"name": "Tamil", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“œ"},
        "marathi": {"name": "Marathi", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“„"},
        "gujarati": {"name": "Gujarati", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“‹"},
        "kannada": {"name": "Kannada", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“‘"},
        "malayalam": {"name": "Malayalam", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ““"},
        "odia": {"name": "Odia", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“•"},
        "punjabi": {"name": "Punjabi", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“—"},
        "assamese": {"name": "Assamese", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“˜"},
        "urdu": {"name": "Urdu", "flag": "๐Ÿ‡ต๐Ÿ‡ฐ", "emoji": "๐Ÿ“™"},
        "maithili": {"name": "Maithili", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“”"},
        "santali": {"name": "Santali", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“’"},
        "kashmiri": {"name": "Kashmiri", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“š"},
        "nepali": {"name": "Nepali", "flag": "๐Ÿ‡ณ๐Ÿ‡ต", "emoji": "๐Ÿ“–"},
        "sindhi": {"name": "Sindhi", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“"},
        "konkani": {"name": "Konkani", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "โœ๏ธ"},
        "dogri": {"name": "Dogri", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“œ"},
        "manipuri": {"name": "Manipuri", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“„"},
        "bodo": {"name": "Bodo", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“‹"},
        "sanskrit": {"name": "Sanskrit", "flag": "๐Ÿ‡ฎ๐Ÿ‡ณ", "emoji": "๐Ÿ“œ"}
    }
    
    return {
        "languages": languages,
        "count": len(languages),
        "emoji": "๐ŸŒ",
        "message": f"๐ŸŒ Supporting {len(languages)} languages!"
    }


# ๐Ÿฅ Health check endpoint
@app.get("/health")
async def health_check():
    """๐Ÿฅ Health check with status"""
    return {
        "status": "โœ… healthy",
        "service": "๐ŸŽฏ EKALAVYA",
        "version": "๐Ÿ“ฆ 3.0.0",
        "emoji": "๐ŸŸข",
        "message": "๐ŸŸข All systems operational!"
    }


# ๐ŸŽฏ Main entry point
if __name__ == "__main__":
    import uvicorn
    print("""
    โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
    โ•‘                                                           โ•‘
    โ•‘   ๐ŸŽฏ  EKALAVYA - AI Teaching Assistant                   โ•‘
    โ•‘                                                           โ•‘
    โ•‘   ๐ŸŒŸ  Multi-Modal โ€ข Multi-Lingual โ€ข Memory-Powered       โ•‘
    โ•‘                                                           โ•‘
    โ•‘   ๐Ÿ›ก๏ธ  Safe โ€ข ๐ŸŽ“ Educational โ€ข ๐Ÿ’ Friendly                โ•‘
    โ•‘                                                           โ•‘
    โ•‘   ๐Ÿ“š  API Docs: http://localhost:8000/docs               โ•‘
    โ•‘                                                           โ•‘
    โ•‘   ๐ŸŒ  Supporting 23 Indian Languages                     โ•‘
    โ•‘                                                           โ•‘
    โ•‘   ๐Ÿง   1M Token Context Window                            โ•‘
    โ•‘                                                           โ•‘
    โ•‘   ๐Ÿ”’  100% Private & Secure                              โ•‘
    โ•‘                                                           โ•‘
    โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    """)
    uvicorn.run(app, host="0.0.0.0", port=8000)

# ๐ŸŽฅ VIDEO AI ENDPOINTS

from model.video_ai import VideoAnalyzer, CameraProcessor

# ๐ŸŽฌ Initialize video AI
video_analyzer = VideoAnalyzer()
camera_processor = CameraProcessor()

class VideoRequest(BaseModel):
    """๐ŸŽฅ Video processing request"""
    video_path: str
    operation: str = "analyze"  # analyze, enhance, stabilize, remove_objects, extract_info

class RealTimeVideoRequest(BaseModel):
    """๐Ÿ“บ Real-time video request"""
    source: int = 0  # 0 for camera, other for screen
    duration: int = 30  # seconds

# ๐ŸŽฌ Video Analysis endpoint
@app.post("/video/analyze")
async def analyze_video(request: VideoRequest):
    """๐ŸŽฌ Analyze video content with AI"""
    try:
        result = video_analyzer.analyze_video_content(request.video_path)
        return {
            "status": "โœ… success",
            "analysis": result,
            "emoji": "๐ŸŽฌ",
            "message": "๐ŸŽฌ Video analysis complete!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Video analysis failed: {str(e)}")

# ๐ŸŽจ Video Enhancement endpoint
@app.post("/video/enhance")
async def enhance_video(request: VideoRequest):
    """๐ŸŽฏ Enhance video quality"""
    try:
        output_path = f"enhanced_{request.video_path.split('/')[-1]}"
        result = video_analyzer.enhance_video_quality(request.video_path, output_path)
        return {
            "status": "โœ… success",
            "output_file": output_path,
            "enhancements": result["enhancements"],
            "emoji": "๐ŸŽฏ",
            "message": "๐ŸŽฏ Video enhanced successfully!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Video enhancement failed: {str(e)}")

# ๐Ÿ“บ Video Stabilization endpoint
@app.post("/video/stabilize")
async def stabilize_video(request: VideoRequest):
    """๐Ÿ“บ Stabilize shaky video"""
    try:
        output_path = f"stabilized_{request.video_path.split('/')[-1]}"
        result = video_analyzer.stabilize_video(request.video_path, output_path)
        return {
            "status": "โœ… success",
            "output_file": output_path,
            "stabilization_level": result["stabilization_level"],
            "emoji": "๐Ÿ“บ",
            "message": "๐Ÿ“บ Video stabilized successfully!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Video stabilization failed: {str(e)}")

# ๐ŸŽจ Object Removal endpoint
@app.post("/video/remove-objects")
async def remove_objects(request: VideoRequest):
    """๐ŸŽจ Remove objects from video"""
    try:
        output_path = f"cleaned_{request.video_path.split('/')[-1]}"
        result = video_analyzer.remove_objects(request.video_path, output_path)
        return {
            "status": "โœ… success",
            "output_file": output_path,
            "frames_processed": result["frames_processed"],
            "emoji": "๐ŸŽจ",
            "message": "๐ŸŽจ Objects removed successfully!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Object removal failed: {str(e)}")

# ๐Ÿ“Š Information Extraction endpoint
@app.post("/video/extract-info")
async def extract_video_info(request: VideoRequest):
    """๐Ÿ“Š Extract information from video"""
    try:
        result = video_analyzer.extract_information(request.video_path)
        return {
            "status": "โœ… success",
            "extracted_info": result,
            "emoji": "๐Ÿ“Š",
            "message": "๐Ÿ“Š Information extracted successfully!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Information extraction failed: {str(e)}")

# ๐Ÿ“บ Real-time Video Analysis endpoint
@app.post("/video/realtime")
async def real_time_video(request: RealTimeVideoRequest):
    """๐Ÿ“บ Real-time video analysis from camera or screen"""
    try:
        result = video_analyzer.real_time_analysis(source=request.source)
        return {
            "status": "โœ… success",
            "frames_analyzed": result["frames_analyzed"],
            "analysis_results": result["analysis_results"][:10],  # Last 10 results
            "emoji": "๐Ÿ“บ",
            "message": "๐Ÿ“บ Real-time analysis complete!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Real-time analysis failed: {str(e)}")

# ๐Ÿ“ท Camera Processing endpoint
@app.post("/camera/process")
async def process_camera():
    """๐Ÿ“ท Process camera frame for visual recognition"""
    try:
        # Capture frame from camera
        import cv2
        cap = cv2.VideoCapture(0)
        ret, frame = cap.read()
        cap.release()
        
        if not ret:
            raise HTTPException(status_code=500, detail="โŒ Cannot capture from camera")
        
        # Process frame
        result = camera_processor.process_camera_frame(frame)
        recognition = camera_processor.recognize_visual_elements(frame)
        
        return {
            "status": "โœ… success",
            "frame_analysis": result,
            "visual_recognition": recognition,
            "emoji": "๐Ÿ“ท",
            "message": "๐Ÿ“ท Camera frame processed successfully!"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Camera processing failed: {str(e)}")

# ๐ŸŽฅ Video Features Summary endpoint
@app.get("/video/features")
async def get_video_features():
    """๐ŸŽฅ Get all video AI features"""
    features = {
        "video_analysis": {
            "emoji": "๐ŸŽฌ",
            "description": "Understand and analyze video content",
            "capabilities": [
                "Scene detection",
                "Object recognition",
                "Motion analysis",
                "Quality assessment",
                "Content classification"
            ]
        },
        "video_enhancement": {
            "emoji": "๐ŸŽฏ",
            "description": "Enhance video quality",
            "capabilities": [
                "Brightness adjustment",
                "Color correction",
                "Sharpening",
                "Contrast enhancement",
                "Noise reduction"
            ]
        },
        "video_stabilization": {
            "emoji": "๐Ÿ“บ",
            "description": "Stabilize shaky video",
            "capabilities": [
                "Motion compensation",
                "Frame alignment",
                "Smooth transitions",
                "Jitter removal",
                "Professional stabilization"
            ]
        },
        "object_removal": {
            "emoji": "๐ŸŽจ",
            "description": "Remove unwanted objects",
            "capabilities": [
                "Object detection",
                "Smart inpainting",
                "Background reconstruction",
                "Seamless removal",
                "Batch processing"
            ]
        },
        "information_extraction": {
            "emoji": "๐Ÿ“Š",
            "description": "Extract information from video",
            "capabilities": [
                "Text recognition (OCR)",
                "Data extraction",
                "Pattern detection",
                "Key moment identification",
                "Metadata analysis"
            ]
        },
        "real_time_analysis": {
            "emoji": "๐Ÿ“บ",
            "description": "Real-time video processing",
            "capabilities": [
                "Live camera feed",
                "Screen share analysis",
                "Instant object detection",
                "Real-time classification",
                "Live streaming support"
            ]
        },
        "camera_processing": {
            "emoji": "๐Ÿ“ท",
            "description": "Camera and visual recognition",
            "capabilities": [
                "Face detection",
                "Object recognition",
                "Scene classification",
                "Visual element detection",
                "Real-time processing"
            ]
        }
    }
    
    return {
        "features": features,
        "total_features": len(features),
        "emoji": "๐ŸŽฅ",
        "message": "๐ŸŽฅ Complete video AI suite available!"
    }

# ๐Ÿ’ป CODING AI ENDPOINTS

from model.coding_ai import CodingAI

# ๐Ÿง‘โ€๐Ÿ’ป Initialize coding AI
coding_ai = CodingAI()

class CodingRequest(BaseModel):
    """๐Ÿ’ป Coding request"""
    code: str
    language: str = "python"
    operation: str = "debug"  # debug, refactor, analyze, generate
    task: str = ""

class CodebaseRequest(BaseModel):
    """๐Ÿ—๏ธ Codebase analysis request"""
    project_path: str

class AutonomousRequest(BaseModel):
    """๐Ÿค– Autonomous task request"""
    task: str
    project_path: str = ""

# ๐Ÿ’ป Code analysis endpoint
@app.post("/coding/analyze")
async def analyze_code(request: CodingRequest):
    """๐Ÿ’ป Analyze and debug code"""
    try:
        if request.operation == "debug":
            result = coding_ai.debug_code(request.code, request.task)
        elif request.operation == "refactor":
            result = coding_ai.refactor_code(request.code, request.language, request.task)
        elif request.operation == "generate":
            result = coding_ai.generate_code(request.task, request.language)
        else:
            result = {"status": "โŒ unknown operation"}
        
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")

# ๐Ÿ—๏ธ Codebase analysis endpoint
@app.post("/coding/codebase")
async def analyze_codebase(request: CodebaseRequest):
    """๐Ÿ—๏ธ Analyze entire codebase"""
    try:
        result = coding_ai.analyze_codebase(request.project_path)
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")

# ๐Ÿค– Autonomous coding endpoint
@app.post("/coding/autonomous")
async def autonomous_coding(request: AutonomousRequest):
    """๐Ÿค– Execute autonomous coding task"""
    try:
        result = coding_ai.autonomous_task(request.task, request.project_path)
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")

# ๐Ÿ–ผ๏ธ VISION AI ENDPOINTS

from model.vision_ai import VisionAI

# ๐ŸŽจ Initialize vision AI
vision_ai = VisionAI()

class ImageGenerationRequest(BaseModel):
    """๐ŸŽจ Image generation request"""
    prompt: str
    style: str = "realistic"
    size: List[int] = [512, 512]

class ImageAnalysisRequest(BaseModel):
    """๐Ÿ‘๏ธ Image analysis request"""
    image_data: str

class ImageProcessingRequest(BaseModel):
    """๐Ÿ”ง Image processing request"""
    image_data: str
    operation: str = "enhance"  # enhance, resize, grayscale, blur, sharpen, edge_detect

# ๐ŸŽจ Image generation endpoint
@app.post("/vision/generate")
async def generate_image(request: ImageGenerationRequest):
    """๐ŸŽจ Generate image from text"""
    try:
        result = vision_ai.generate_image(
            request.prompt,
            request.style,
            tuple(request.size)
        )
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")

# ๐Ÿ‘๏ธ Image analysis endpoint
@app.post("/vision/analyze")
async def analyze_image(request: ImageAnalysisRequest):
    """๐Ÿ‘๏ธ Analyze image content"""
    try:
        result = vision_ai.analyze_image(request.image_data)
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")

# ๐Ÿ”ง Image processing endpoint
@app.post("/vision/process")
async def process_image(request: ImageProcessingRequest):
    """๐Ÿ”ง Process image"""
    try:
        result = vision_ai.process_image(request.image_data, request.operation)
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"โŒ Error: {str(e)}")

# ๐ŸŽฏ ALL CAPABILITIES ENDPOINT

@app.get("/capabilities")
async def get_all_capabilities():
    """๐ŸŽฏ Get all EKALAVYA capabilities"""
    return {
        "name": "๐ŸŽฏ EKALAVYA",
        "version": "๐Ÿ“ฆ 3.0",
        "status": "โœ… Most Powerful AI",
        "capabilities": {
            "๐Ÿ’ป Coding": {
                "emoji": "๐Ÿ’ป",
                "features": [
                    "๐Ÿ—๏ธ Large project understanding",
                    "๐Ÿ”ง Code refactoring",
                    "๐Ÿ› Debugging & bug fixing",
                    "๐Ÿ’ป Code generation",
                    "๐Ÿค– Autonomous coding agent",
                    "๐Ÿงช Test generation",
                    "๐Ÿ“š Documentation"
                ],
                "better_than": "Claude, ChatGPT"
            },
            "๐Ÿ–ผ๏ธ Image": {
                "emoji": "๐Ÿ–ผ๏ธ",
                "features": [
                    "๐ŸŽจ Image generation",
                    "๐Ÿ‘๏ธ Image analysis",
                    "๐Ÿ”ง Image processing",
                    "๐Ÿ“Š Visual understanding",
                    "๐ŸŽจ Style transfer"
                ],
                "better_than": "Gemini, ChatGPT"
            },
            "๐ŸŽฅ Video": {
                "emoji": "๐ŸŽฅ",
                "features": [
                    "๐ŸŽฌ Video analysis",
                    "๐ŸŽฏ Video enhancement",
                    "๐Ÿ“บ Video stabilization",
                    "๐ŸŽจ Object removal",
                    "๐Ÿ“Š Information extraction",
                    "๐Ÿ“บ Real-time analysis",
                    "๐Ÿ“ท Camera processing"
                ],
                "better_than": "Gemini, Samsung, iPhone"
            },
            "๐ŸŽ“ Teaching": {
                "emoji": "๐ŸŽ“",
                "features": [
                    "๐Ÿ” Mistake detection",
                    "โœ… Instant corrections",
                    "๐Ÿ“š Detailed explanations",
                    "๐Ÿ’ช Encouragement",
                    "๐ŸŽฏ Personalized learning"
                ],
                "better_than": "All others"
            },
            "๐Ÿง  Memory": {
                "emoji": "๐Ÿง ",
                "features": [
                    "๐Ÿ“Š Progress tracking",
                    "๐Ÿ“ˆ Improvement monitoring",
                    "๐ŸŽฏ Weak area identification",
                    "๐Ÿ’ฌ Conversation memory",
                    "๐Ÿ” Pattern analysis"
                ],
                "better_than": "Claude, ChatGPT, Gemini"
            },
            "๐Ÿ’ Styles": {
                "emoji": "๐Ÿ’",
                "features": [
                    "๐Ÿ‘ซ Friend style",
                    "๐Ÿ‘จโ€๐Ÿซ Teacher style",
                    "๐Ÿ’• Lover style",
                    "๐ŸŽ“ Mentor style"
                ],
                "better_than": "All others (unique)"
            },
            "๐ŸŒ Languages": {
                "emoji": "๐ŸŒ",
                "features": [
                    "๐Ÿ‡ฎ๐Ÿ‡ณ 23 Indian languages",
                    "๐Ÿ‡ฌ๐Ÿ‡ง English",
                    "๐Ÿ”ค Multi-lingual support"
                ],
                "better_than": "All others"
            },
            "๐Ÿ›ก๏ธ Safety": {
                "emoji": "๐Ÿ›ก๏ธ",
                "features": [
                    "๐Ÿ›ก๏ธ Scam detection",
                    "๐Ÿ’ป Hacking prevention",
                    "๐Ÿ”’ Privacy protection",
                    "โœ… Ethical guidelines",
                    "๐Ÿ“‹ Privacy policy"
                ],
                "better_than": "All others"
            },
            "๐Ÿง  Reasoning": {
                "emoji": "๐Ÿง ",
                "features": [
                    "๐Ÿ’ญ Deep reasoning",
                    "๐Ÿ” Step-by-step analysis",
                    "๐ŸŽฏ Problem solving",
                    "๐Ÿ“Š Complex tasks"
                ],
                "better_than": "ChatGPT"
            },
            "โœ๏ธ Writing": {
                "emoji": "โœ๏ธ",
                "features": [
                    "๐Ÿ“ Creative writing",
                    "๐Ÿ“š Technical writing",
                    "๐ŸŽฏ Precise editing",
                    "๐Ÿ’ก Style adaptation"
                ],
                "better_than": "Claude"
            }
        },
        "emoji": "๐Ÿ†",
        "message": "๐Ÿ† EKALAVYA - The Most Powerful AI Assistant!"
    }