vinaymodel / api.py
hackerbhai's picture
๐ŸŽฏ Add api.py - Complete AI capabilities
bdd1932 verified
Raw
History Blame Contribute Delete
31.4 kB
#!/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!"
}