Spaces:
Sleeping
Sleeping
Update language_detector.py
Browse files- language_detector.py +113 -34
language_detector.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# language_detector.py
|
| 2 |
from langdetect import detect, DetectorFactory
|
| 3 |
import re
|
| 4 |
|
|
@@ -7,7 +7,6 @@ DetectorFactory.seed = 0
|
|
| 7 |
def detect_input_language(text):
|
| 8 |
"""User input ki language detect kare"""
|
| 9 |
try:
|
| 10 |
-
# Clean text
|
| 11 |
clean_text = re.sub(r'[^\w\s]', '', text)
|
| 12 |
if not clean_text.strip():
|
| 13 |
return 'mixed'
|
|
@@ -23,45 +22,125 @@ def detect_input_language(text):
|
|
| 23 |
return 'mixed'
|
| 24 |
|
| 25 |
def get_system_prompt(lang_mode, username):
|
| 26 |
-
"""
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
1.
|
| 34 |
-
2.
|
| 35 |
-
3.
|
| 36 |
-
4.
|
| 37 |
-
"""
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
2. Code: If {username} asks for code, provide 350+ lines of production-ready Python script
|
| 46 |
-
3. Style: Professional, powerful, direct (Max 4 lines)
|
| 47 |
-
4. Persona: Talk like a Master AI, not a basic chatbot
|
| 48 |
"""
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
2. Code: If {username} asks for code, provide 350+ lines of production-ready Python script
|
| 57 |
-
3. Style: Professional, powerful, direct (Max 4 lines)
|
| 58 |
-
4. Persona: Talk like a Master AI, not a basic chatbot
|
| 59 |
-
"""
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# language_detector.py - FINAL EXPERT VERSION
|
| 2 |
from langdetect import detect, DetectorFactory
|
| 3 |
import re
|
| 4 |
|
|
|
|
| 7 |
def detect_input_language(text):
|
| 8 |
"""User input ki language detect kare"""
|
| 9 |
try:
|
|
|
|
| 10 |
clean_text = re.sub(r'[^\w\s]', '', text)
|
| 11 |
if not clean_text.strip():
|
| 12 |
return 'mixed'
|
|
|
|
| 22 |
return 'mixed'
|
| 23 |
|
| 24 |
def get_system_prompt(lang_mode, username):
|
| 25 |
+
"""AI ko expert coding ke liye train kare"""
|
| 26 |
|
| 27 |
+
# COMMON RULES FOR ALL LANGUAGES
|
| 28 |
+
common_rules = f"""
|
| 29 |
+
YOU ARE AUMCORE AI - SENIOR AI ARCHITECT & CODING EXPERT.
|
| 30 |
+
USER: {username}.
|
| 31 |
|
| 32 |
+
ABSOLUTE RULES:
|
| 33 |
+
1. CODING: When user asks for code, provide FULL PRODUCTION-READY CODE (300+ lines).
|
| 34 |
+
2. CODE FORMAT: Output ONLY RAW CODE, NO markdown blocks (```python```), NO explanations.
|
| 35 |
+
3. CODE QUALITY: Include error handling, logging, documentation, modular functions.
|
| 36 |
+
4. RESPONSE STYLE: Concise, powerful, direct (Max 4 lines for non-code responses).
|
|
|
|
| 37 |
|
| 38 |
+
CODING EXAMPLES:
|
| 39 |
+
- User: "google drive mount code"
|
| 40 |
+
- You: "from google.colab import drive\ndrive.mount('/content/gdrive')"
|
| 41 |
|
| 42 |
+
- User: "web app code"
|
| 43 |
+
- You: 300+ lines of Flask/FastAPI code
|
|
|
|
|
|
|
|
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
+
# LANGUAGE SPECIFIC INSTRUCTIONS
|
| 47 |
+
language_instructions = {
|
| 48 |
+
'hindi': """
|
| 49 |
+
भाषा: 100% हिंदी (कोड के अलावा)
|
| 50 |
+
उदाहरण: "नमस्ते, कोड बताओ" → आप सिर्फ कोड दो, हिंदी explanation नहीं
|
| 51 |
+
""",
|
| 52 |
+
|
| 53 |
+
'english': """
|
| 54 |
+
Language: 100% English (except code)
|
| 55 |
+
Example: "hello, give me code" → You provide only code, no English explanation
|
| 56 |
+
""",
|
| 57 |
+
|
| 58 |
+
'mixed': """
|
| 59 |
+
Language: 60% English + 40% Hindi blended
|
| 60 |
+
Example: "hi bhai, code de do" → You provide only code, no mixed explanation
|
| 61 |
+
"""
|
| 62 |
+
}
|
| 63 |
|
| 64 |
+
# FINAL PROMPT
|
| 65 |
+
final_prompt = common_rules + language_instructions.get(lang_mode, language_instructions['mixed'])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
return final_prompt.strip()
|
| 68 |
+
|
| 69 |
+
# TEST FUNCTION FOR CODE GENERATION
|
| 70 |
+
def generate_expert_code(task_description):
|
| 71 |
+
"""Expert code generation logic (for future enhancement)"""
|
| 72 |
+
code_templates = {
|
| 73 |
+
'web': """
|
| 74 |
+
from fastapi import FastAPI, HTTPException
|
| 75 |
+
from pydantic import BaseModel
|
| 76 |
+
import uvicorn
|
| 77 |
+
import logging
|
| 78 |
+
|
| 79 |
+
logging.basicConfig(level=logging.INFO)
|
| 80 |
+
logger = logging.getLogger(__name__)
|
| 81 |
+
|
| 82 |
+
app = FastAPI(title="Professional Web Service")
|
| 83 |
+
|
| 84 |
+
class Item(BaseModel):
|
| 85 |
+
name: str
|
| 86 |
+
price: float
|
| 87 |
+
quantity: int
|
| 88 |
+
|
| 89 |
+
@app.get("/")
|
| 90 |
+
async def root():
|
| 91 |
+
return {"message": "Welcome to AumCore AI Web Service"}
|
| 92 |
+
|
| 93 |
+
@app.post("/items/")
|
| 94 |
+
async def create_item(item: Item):
|
| 95 |
+
try:
|
| 96 |
+
logger.info(f"Creating item: {item.name}")
|
| 97 |
+
# Business logic here
|
| 98 |
+
return {"status": "success", "item": item.dict()}
|
| 99 |
+
except Exception as e:
|
| 100 |
+
logger.error(f"Error: {e}")
|
| 101 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 102 |
+
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 105 |
+
""",
|
| 106 |
+
'data': """
|
| 107 |
+
import pandas as pd
|
| 108 |
+
import numpy as np
|
| 109 |
+
from sklearn.model_selection import train_test_split
|
| 110 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 111 |
+
import matplotlib.pyplot as plt
|
| 112 |
+
import seaborn as sns
|
| 113 |
+
|
| 114 |
+
class DataAnalyzer:
|
| 115 |
+
def __init__(self, filepath):
|
| 116 |
+
self.df = pd.read_csv(filepath)
|
| 117 |
+
self.results = {}
|
| 118 |
+
|
| 119 |
+
def analyze(self):
|
| 120 |
+
# Comprehensive data analysis
|
| 121 |
+
self.results['shape'] = self.df.shape
|
| 122 |
+
self.results['columns'] = list(self.df.columns)
|
| 123 |
+
self.results['missing'] = self.df.isnull().sum()
|
| 124 |
+
return self.results
|
| 125 |
+
|
| 126 |
+
def visualize(self):
|
| 127 |
+
# Professional visualizations
|
| 128 |
+
fig, axes = plt.subplots(2, 2, figsize=(15, 10))
|
| 129 |
+
# Plotting logic...
|
| 130 |
+
plt.tight_layout()
|
| 131 |
+
return fig
|
| 132 |
+
|
| 133 |
+
# Usage example
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
analyzer = DataAnalyzer("data.csv")
|
| 136 |
+
print(analyzer.analyze())
|
| 137 |
+
"""
|
| 138 |
}
|
| 139 |
|
| 140 |
+
# Simple keyword matching (can be enhanced with AI)
|
| 141 |
+
if 'web' in task_description.lower() or 'app' in task_description.lower():
|
| 142 |
+
return code_templates['web']
|
| 143 |
+
elif 'data' in task_description.lower() or 'analy' in task_description.lower():
|
| 144 |
+
return code_templates['data']
|
| 145 |
+
else:
|
| 146 |
+
return code_templates['web'] # Default
|