AumCore-AI / core /language_detector.py
AumCoreAI's picture
Update core/language_detector.py
eb81b58 verified
raw
history blame
15.4 kB
# SIMPLE CODE GENERATOR WITH COLORFUL SYNTAX HIGHLIGHTING
def generate_basic_code(task):
"""Generate basic code templates with colorful syntax highlighting"""
task_lower = task.lower()
# GitHub-like syntax highlighting colors
colors = {
'keyword': '#569CD6', # def, import, from
'function': '#DCDCAA', # function names
'string': '#CE9178', # strings
'comment': '#608B4E', # comments
'number': '#B5CEA8', # numbers
'operator': '#D4D4D4', # =, (), ., :
'class': '#4EC9B0', # class names
'decorator': '#C586C0', # @app.get
}
# Colorful Google Drive Mount Code
drive_code = f'''<div class="code-container">
<div class="code-header">
<div class="code-lang"><i class="fab fa-google-drive"></i> Google Colab</div>
<button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy"></i> Copy Code</button>
</div>
<pre><code style="color: #f8f8f2; background: #0d1117; padding: 20px; border-radius: 0 0 8px 8px; display: block; overflow-x: auto; font-family: 'Fira Code', monospace; line-height: 1.5;">
<span style="color: {colors['comment']}"># Mount Google Drive in Google Colab</span>
<span style="color: {colors['keyword']}">from</span> <span style="color: {colors['function']}">google.colab</span> <span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">drive</span>
<span style="color: {colors['function']}">drive</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">mount</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&#x27;/content/gdrive&#x27;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['comment']}"># After authorization, access your drive</span>
<span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">os</span>
<span style="color: {colors['comment']}"># List files in drive</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;Mounted at: /content/gdrive&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;Files:&quot;</span><span style="color: {colors['operator']}">,</span> <span style="color: {colors['function']}">os</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">listdir</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&#x27;/content/gdrive&#x27;</span><span style="color: {colors['operator']}">))</span>
</code></pre>
</div>'''
# Colorful FastAPI Web App Code
web_code = f'''<div class="code-container">
<div class="code-header">
<div class="code-lang"><i class="fas fa-globe"></i> FastAPI Web App</div>
<button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy"></i> Copy Code</button>
</div>
<pre><code style="color: #f8f8f2; background: #0d1117; padding: 20px; border-radius: 0 0 8px 8px; display: block; overflow-x: auto; font-family: 'Fira Code', monospace; line-height: 1.5;">
<span style="color: {colors['keyword']}">from</span> <span style="color: {colors['function']}">fastapi</span> <span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">FastAPI</span>
<span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">uvicorn</span>
<span style="color: {colors['comment']}"># Create FastAPI app</span>
<span style="color: {colors['function']}">app</span> <span style="color: {colors['operator']}">=</span> <span style="color: {colors['class']}">FastAPI</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['decorator']}">@app</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">get</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;/&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['keyword']}">def</span> <span style="color: {colors['function']}">home</span><span style="color: {colors['operator']}">():</span>
<span style="color: {colors['keyword']}">return</span> <span style="color: {colors['operator']}">{{</span><span style="color: {colors['string']}">&quot;message&quot;</span><span style="color: {colors['operator']}">:</span> <span style="color: {colors['string']}">&quot;Hello from AumCore AI! πŸš€&quot;</span><span style="color: {colors['operator']}">}}</span>
<span style="color: {colors['decorator']}">@app</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">get</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;/health&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['keyword']}">def</span> <span style="color: {colors['function']}">health_check</span><span style="color: {colors['operator']}">():</span>
<span style="color: {colors['keyword']}">return</span> <span style="color: {colors['operator']}">{{</span><span style="color: {colors['string']}">&quot;status&quot;</span><span style="color: {colors['operator']}">:</span> <span style="color: {colors['string']}">&quot;healthy&quot;</span><span style="color: {colors['operator']}">,</span> <span style="color: {colors['string']}">&quot;service&quot;</span><span style="color: {colors['operator']}">:</span> <span style="color: {colors['string']}">&quot;AumCore AI&quot;</span><span style="color: {colors['operator']}">}}</span>
<span style="color: {colors['keyword']}">if</span> <span style="color: {colors['variable']}">__name__</span> <span style="color: {colors['operator']}">==</span> <span style="color: {colors['string']}">&quot;__main__&quot;</span><span style="color: {colors['operator']}">:</span>
<span style="color: {colors['function']}">uvicorn</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">run</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['function']}">app</span><span style="color: {colors['operator']}">,</span> <span style="color: {colors['variable']}">host</span><span style="color: {colors['operator']}">=</span><span style="color: {colors['string']}">&quot;0.0.0.0&quot;</span><span style="color: {colors['operator']}">,</span> <span style="color: {colors['variable']}">port</span><span style="color: {colors['operator']}">=</span><span style="color: {colors['number']}">8000</span><span style="color: {colors['operator']}">)</span>
</code></pre>
</div>'''
# Colorful Data Analysis Code
data_code = f'''<div class="code-container">
<div class="code-header">
<div class="code-lang"><i class="fas fa-chart-bar"></i> Data Analysis</div>
<button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy"></i> Copy Code</button>
</div>
<pre><code style="color: #f8f8f2; background: #0d1117; padding: 20px; border-radius: 0 0 8px 8px; display: block; overflow-x: auto; font-family: 'Fira Code', monospace; line-height: 1.5;">
<span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">pandas</span> <span style="color: {colors['keyword']}">as</span> <span style="color: {colors['function']}">pd</span>
<span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">numpy</span> <span style="color: {colors['keyword']}">as</span> <span style="color: {colors['function']}">np</span>
<span style="color: {colors['keyword']}">import</span> <span style="color: {colors['function']}">matplotlib.pyplot</span> <span style="color: {colors['keyword']}">as</span> <span style="color: {colors['function']}">plt</span>
<span style="color: {colors['comment']}"># Load dataset</span>
<span style="color: {colors['function']}">df</span> <span style="color: {colors['operator']}">=</span> <span style="color: {colors['function']}">pd</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">read_csv</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;data.csv&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['comment']}"># Basic information</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">f&quot;πŸ“Š Dataset Shape: </span><span style="color: {colors['operator']}">{{</span><span style="color: {colors['function']}">df</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">shape</span><span style="color: {colors['operator']}">}}</span><span style="color: {colors['string']}">&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">f&quot;πŸ“‹ Columns: </span><span style="color: {colors['operator']}">{{</span><span style="color: {colors['function']}">list</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['function']}">df</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">columns</span><span style="color: {colors['operator']}">)}}</span><span style="color: {colors['string']}">&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;\\nπŸ“ˆ Basic Statistics:&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors='function'}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['function']}">df</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">describe</span><span style="color: {colors['operator']}">())</span>
<span style="color: {colors['comment']}"># Check for missing values</span>
<span style="color: {colors['function']}">missing</span> <span style="color: {colors['operator']}">=</span> <span style="color: {colors['function']}">df</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">isnull</span><span style="color: {colors['operator']}">()</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">sum</span><span style="color: {colors['operator']}">()</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">f&quot;\\n⚠️ Missing Values:\\n</span><span style="color: {colors['operator']}">{{</span><span style="color: {colors['function']}">missing</span><span style="color: {colors['operator']}">}}</span><span style="color: {colors['string']}">&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['comment']}"># Create a simple visualization</span>
<span style="color: {colors['function']}">plt</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">figure</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['variable']}">figsize</span><span style="color: {colors['operator']}">=</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['number']}">10</span><span style="color: {colors['operator']}">,</span> <span style="color: {colors['number']}">6</span><span style="color: {colors['operator']}">))</span>
<span style="color: {colors['function']}">df</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">hist</span><span style="color: {colors['operator']}">()</span>
<span style="color: {colors['function']}">plt</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">tight_layout</span><span style="color: {colors['operator']}">()</span>
<span style="color: {colors['function']}">plt</span><span style="color: {colors['operator']}">.</span><span style="color: {colors['function']}">show</span><span style="color: {colors['operator']}">()</span>
</code></pre>
</div>'''
# Determine which code to return
if 'drive' in task_lower or 'mount' in task_lower:
return drive_code
elif 'web' in task_lower or 'app' in task_lower or 'api' in task_lower:
return web_code
elif 'data' in task_lower or 'analy' in task_lower or 'pandas' in task_lower:
return data_code
else:
# Default colorful hello world
return f'''<div class="code-container">
<div class="code-header">
<div class="code-lang"><i class="fas fa-code"></i> Python</div>
<button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy"></i> Copy Code</button>
</div>
<pre><code style="color: #f8f8f2; background: #0d1117; padding: 20px; border-radius: 0 0 8px 8px; display: block; overflow-x: auto; font-family: 'Fira Code', monospace; line-height: 1.5;">
<span style="color: {colors['keyword']}">def</span> <span style="color: {colors['function']}">hello_aumcore</span><span style="color: {colors['operator']}">():</span>
<span style="color: {colors['string']}">&quot;&quot;&quot;</span>
<span style="color: {colors['string']}> AumCore AI Sample Function</span>
<span style="color: {colors['string']}> With GitHub-like syntax highlighting</span>
<span style="color: {colors['string']}> &quot;&quot;&quot;</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;πŸš€ Welcome to AumCore AI!&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}">&quot;🌈 Colorful syntax highlighting enabled&quot;</span><span style="color: {colors['operator']}">)</span>
<span style="color: {colors['keyword']}">return</span> <span style="color: {colors['string']}">&quot;Code execution successful!&quot;</span>
<span style="color: {colors['comment']}># Execute the function</span>
<span style="color: {colors['function']}">result</span> <span style="color: {colors['operator']}">=</span> <span style="color: {colors['function']}">hello_aumcore</span><span style="color: {colors['operator']}">()</span>
<span style="color: {colors['function']}">print</span><span style="color: {colors['operator']}">(</span><span style="color: {colors['string']}>f&quot;βœ… Result: </span><span style="color: {colors['operator']}">{{</span><span style="color: {colors['function']}">result</span><span style="color: {colors['operator']}">}}</span><span style="color: {colors['string']}">&quot;</span><span style="color: {colors['operator']}">)</span>
</code></pre>
</div>'''