Spaces:
Running
Running
Update index.html
#1
by Hanuman2 - opened
- .gitattributes +34 -6
- .github/workflows/main.yml +0 -47
- Dockerfile +3 -33
- README.md +11 -6
- app.py +88 -284
- index.html +0 -0
- logo.png +0 -3
- requirements.txt +0 -4
.gitattributes
CHANGED
|
@@ -1,7 +1,35 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.
|
| 3 |
-
*.
|
| 4 |
-
*.
|
| 5 |
-
*.
|
| 6 |
-
*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/main.yml
DELETED
|
@@ -1,47 +0,0 @@
|
|
| 1 |
-
name: Deploy to Hugging Face Space
|
| 2 |
-
|
| 3 |
-
on:
|
| 4 |
-
push:
|
| 5 |
-
branches: [ main ]
|
| 6 |
-
workflow_dispatch:
|
| 7 |
-
|
| 8 |
-
jobs:
|
| 9 |
-
sync-to-hf:
|
| 10 |
-
runs-on: ubuntu-latest
|
| 11 |
-
steps:
|
| 12 |
-
- name: Checkout Code
|
| 13 |
-
uses: actions/checkout@v3
|
| 14 |
-
|
| 15 |
-
- name: Clean History and Force Push to HF
|
| 16 |
-
env:
|
| 17 |
-
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 18 |
-
run: |
|
| 19 |
-
# 1. गिट कॉन्फ़िगरेशन
|
| 20 |
-
git config --global user.email "divy@vedaalabs.ai"
|
| 21 |
-
git config --global user.name "Divy Patel"
|
| 22 |
-
|
| 23 |
-
# 2. पुरानी हिस्ट्री को पूरी तरह से डिलीट करें और नई शुरुआत करें
|
| 24 |
-
rm -rf .git
|
| 25 |
-
git init
|
| 26 |
-
git branch -M main
|
| 27 |
-
|
| 28 |
-
# 3. LFS सेटअप और ट्रैकिंग (सभी बड़ी फाइलों के लिए)
|
| 29 |
-
git lfs install
|
| 30 |
-
git lfs track "*.ttf"
|
| 31 |
-
git lfs track "*.whl"
|
| 32 |
-
git lfs track "*.png"
|
| 33 |
-
git lfs track "*.jpg"
|
| 34 |
-
git lfs track "*.jpeg"
|
| 35 |
-
git lfs track "*.woff2"
|
| 36 |
-
git lfs track "*.wasm"
|
| 37 |
-
|
| 38 |
-
# 4. सभी फाइलों को नए सिरे से ऐड करें
|
| 39 |
-
git add .gitattributes
|
| 40 |
-
git add .
|
| 41 |
-
|
| 42 |
-
# 5. नया फ्रेश कमिट
|
| 43 |
-
git commit -m "Clean deployment with comprehensive LFS tracking"
|
| 44 |
-
|
| 45 |
-
# 6. हगिंग फेस रिमोट सेट करें और फोर्स पुश करें
|
| 46 |
-
git remote add hf https://user:${HF_TOKEN}@huggingface.co/spaces/Renderlib-dev/CodeVed
|
| 47 |
-
git push -f hf main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dockerfile
CHANGED
|
@@ -1,42 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
# Base image with Python 3.10 and system dependencies
|
| 3 |
-
FROM python:3.10-slim
|
| 4 |
|
| 5 |
-
# Set environment variables
|
| 6 |
-
ENV PYTHONUNBUFFERED=1 \
|
| 7 |
-
PYTHONDONTWRITEBYTECODE=1 \
|
| 8 |
-
PIP_NO_CACHE_DIR=1 \
|
| 9 |
-
PIP_DISABLE_PIP_VERSION_CHECK=1
|
| 10 |
-
|
| 11 |
-
# Set working directory
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
-
# Install system dependencies
|
| 15 |
-
# ffmpeg for pydub, git for renderlib, and other utilities
|
| 16 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 17 |
-
ffmpeg \
|
| 18 |
-
git \
|
| 19 |
-
curl \
|
| 20 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
-
|
| 22 |
-
# Copy requirements first to leverage Docker cache
|
| 23 |
COPY requirements.txt .
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
# Note: renderlib is installed from git, supertonic may download models
|
| 27 |
-
RUN pip install --upgrade pip && \
|
| 28 |
-
pip install -r requirements.txt
|
| 29 |
|
| 30 |
-
# Copy the rest of the application
|
| 31 |
-
COPY app.py .
|
| 32 |
-
COPY index.html .
|
| 33 |
-
|
| 34 |
-
# Expose port 7860 (Hugging Face Spaces standard port)
|
| 35 |
EXPOSE 7860
|
| 36 |
|
| 37 |
-
# Health check
|
| 38 |
-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 39 |
-
CMD curl -f http://localhost:7860/ || exit 1
|
| 40 |
-
|
| 41 |
-
# Run the Flask application
|
| 42 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
|
| 8 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
EXPOSE 7860
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
title: Codeved
|
| 4 |
-
sdk: docker
|
| 5 |
emoji: 🚀
|
| 6 |
-
colorFrom:
|
| 7 |
-
colorTo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Tiranga-advanced-multimodal-AI
|
|
|
|
|
|
|
| 3 |
emoji: 🚀
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
short_description: Demo version of Vedika
|
| 10 |
+
thumbnail: >-
|
| 11 |
+
https://cdn-uploads.huggingface.co/production/uploads/6a0975f9cdda3a9b7e513e3f/-EPyeIHoSfq0qp9ntFw9a.png
|
| 12 |
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,146 +1,61 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
-
import json
|
| 4 |
-
import re
|
| 5 |
-
import io
|
| 6 |
-
import tempfile
|
| 7 |
from datetime import datetime, timedelta, timezone
|
| 8 |
-
from bs4 import BeautifulSoup
|
| 9 |
from flask import Flask, request, Response, stream_with_context, render_template_string
|
| 10 |
-
from supertonic import TTS
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
|
| 14 |
-
# ------
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
print("Loading RenderLib...")
|
| 18 |
-
try:
|
| 19 |
-
from renderlib import RenderLib
|
| 20 |
-
renderer = RenderLib()
|
| 21 |
-
print("RenderLib loaded successfully!")
|
| 22 |
-
except ImportError as e:
|
| 23 |
-
print(f"RenderLib not installed yet or error: {e}")
|
| 24 |
-
renderer = None
|
| 25 |
-
|
| 26 |
-
# ----------------------------------------------------
|
| 27 |
-
# INIT TTS MODEL
|
| 28 |
-
# ----------------------------------------------------
|
| 29 |
-
print("Loading Supertonic TTS Model...")
|
| 30 |
-
try:
|
| 31 |
-
tts = TTS(auto_download=True)
|
| 32 |
-
print("TTS Model loaded successfully!")
|
| 33 |
-
except Exception as e:
|
| 34 |
-
print(f"Error initializing TTS: {e}")
|
| 35 |
-
tts = None
|
| 36 |
-
|
| 37 |
-
VOICES = ["M1", "M2", "M3", "M4", "M5", "F1", "F2", "F3", "F4", "F5"]
|
| 38 |
-
LANGUAGES = {
|
| 39 |
-
"English": "en", "Korean": "ko", "Japanese": "ja", "Arabic": "ar",
|
| 40 |
-
"Bulgarian": "bg", "Czech": "cs", "Danish": "da", "German": "de",
|
| 41 |
-
"Greek": "el", "Spanish": "es", "Estonian": "et", "Finnish": "fi",
|
| 42 |
-
"French": "fr", "Hindi": "hi", "Croatian": "hr", "Hungarian": "hu",
|
| 43 |
-
"Indonesian": "id", "Italian": "it", "Lithuanian": "lt", "Latvian": "lv",
|
| 44 |
-
"Dutch": "nl", "Polish": "pl", "Portuguese": "pt", "Romanian": "ro",
|
| 45 |
-
"Russian": "ru", "Slovak": "sk", "Slovenian": "sl", "Swedish": "sv",
|
| 46 |
-
"Turkish": "tr", "Ukrainian": "uk", "Vietnamese": "vi"
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
VOICE_STYLES_CACHE = {}
|
| 50 |
-
|
| 51 |
-
# ----------------------------------------------------
|
| 52 |
-
# HARDCODED MODEL CONFIGURATION (Directly in code)
|
| 53 |
-
# ----------------------------------------------------
|
| 54 |
-
NVIDIA_API_KEY = os.environ.get("NVIDIA_API_KEY", "") # Secrets se le raha hai
|
| 55 |
-
# Agar API key bhi hardcode karna ho toh upar wali line ko hata kar yah likhein:
|
| 56 |
-
# NVIDIA_API_KEY = "your_actual_api_key_here"
|
| 57 |
|
|
|
|
| 58 |
INVOKE_URL = "https://integrate.api.nvidia.com/v1/chat/completions"
|
| 59 |
-
MODEL_ID = "mistralai/mistral-small-4-119b-2603"
|
| 60 |
|
| 61 |
-
# ------
|
| 62 |
-
|
| 63 |
-
# ----------------------------------------------------
|
| 64 |
-
def get_address_from_coords(lat, lon):
|
| 65 |
-
try:
|
| 66 |
-
url = f"https://nominatim.openstreetmap.org/reverse?format=json&lat={lat}&lon={lon}"
|
| 67 |
-
headers = {'User-Agent': 'CODE_VED_AI_System_by_Divy_Patel'}
|
| 68 |
-
response = requests.get(url, headers=headers, timeout=5)
|
| 69 |
-
data = response.json()
|
| 70 |
-
return data.get('display_name', f"Lat: {lat}, Lon: {lon}")
|
| 71 |
-
except Exception as e:
|
| 72 |
-
return f"Lat: {lat}, Lon: {lon}"
|
| 73 |
|
| 74 |
-
# ------
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
results = []
|
| 79 |
-
serpapi_key = os.environ.get("SERPAPI_KEY")
|
| 80 |
-
if not serpapi_key:
|
| 81 |
-
return results
|
| 82 |
-
|
| 83 |
-
search_query = query
|
| 84 |
-
if user_address:
|
| 85 |
-
local_keywords = ["near", "nearby", "distance", "time", "where"]
|
| 86 |
-
if any(kw in query.lower() for kw in local_keywords):
|
| 87 |
-
search_query = f"{query} near {user_address}"
|
| 88 |
-
|
| 89 |
try:
|
| 90 |
-
params = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
response = requests.get("https://serpapi.com/search", params=params, timeout=10)
|
| 92 |
data = response.json()
|
| 93 |
|
|
|
|
| 94 |
if "organic_results" in data:
|
| 95 |
for item in data["organic_results"]:
|
| 96 |
title = item.get("title", "")
|
| 97 |
link = item.get("link", "")
|
| 98 |
snippet = item.get("snippet", "")
|
|
|
|
| 99 |
if title and snippet:
|
| 100 |
-
results.append({
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
return results
|
| 104 |
|
| 105 |
# ----------------------------------------------------
|
| 106 |
-
# RSS TECH NEWS SCRAPER
|
| 107 |
-
# ----------------------------------------------------
|
| 108 |
-
def get_live_web_data(query):
|
| 109 |
-
url = f"https://news.google.com/rss/search?q={query}&hl=en&gl=IN&ceid=IN:en"
|
| 110 |
-
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
|
| 111 |
-
tech_keywords = ["ai", "artificial intelligence", "smartphone", "mobile", "feature", "whatsapp", "google", "tech", "technology", "gadget", "apple", "nasa"]
|
| 112 |
-
block_keywords = ["share news", "stock"]
|
| 113 |
-
scraped_results = []
|
| 114 |
-
|
| 115 |
-
try:
|
| 116 |
-
response = requests.get(url, headers=headers, timeout=6)
|
| 117 |
-
if response.status_code == 200:
|
| 118 |
-
soup = BeautifulSoup(response.text, "html.parser")
|
| 119 |
-
items = soup.find_all('item')
|
| 120 |
-
for item in items:
|
| 121 |
-
title = item.title.text if item.title else "No Title"
|
| 122 |
-
title_lower = title.lower()
|
| 123 |
-
|
| 124 |
-
if any(b_kw in title_lower for b_kw in block_keywords):
|
| 125 |
-
continue
|
| 126 |
-
if any(t_kw in title_lower for t_kw in tech_keywords):
|
| 127 |
-
link = item.link.text if item.link else "#"
|
| 128 |
-
pub_date = item.pubdate.text if item.pubdate else ""
|
| 129 |
-
source = item.source.text if item.source else "Google News"
|
| 130 |
-
scraped_results.append({
|
| 131 |
-
"title": title,
|
| 132 |
-
"snippet": f"Published: {pub_date} | Source: {source}",
|
| 133 |
-
"link": link
|
| 134 |
-
})
|
| 135 |
-
if len(scraped_results) >= 5:
|
| 136 |
-
break
|
| 137 |
-
except Exception:
|
| 138 |
-
pass
|
| 139 |
-
return scraped_results
|
| 140 |
|
| 141 |
-
# ----------------------------------------------------
|
| 142 |
-
# HOME ROUTE
|
| 143 |
-
# ----------------------------------------------------
|
| 144 |
@app.route('/')
|
| 145 |
def home():
|
| 146 |
try:
|
|
@@ -149,212 +64,101 @@ def home():
|
|
| 149 |
except Exception as e:
|
| 150 |
return f"<h1>System Error</h1><p>index.html missing: {str(e)}</p>"
|
| 151 |
|
| 152 |
-
# ----------------------------------------------------
|
| 153 |
-
# RENDERLIB API ENDPOINT
|
| 154 |
-
# ----------------------------------------------------
|
| 155 |
-
@app.route('/api/render', methods=['POST'])
|
| 156 |
-
def render_content():
|
| 157 |
-
if renderer is None:
|
| 158 |
-
return Response(json.dumps({"error": "RenderLib is not available on the server."}), status=500, mimetype='application/json')
|
| 159 |
-
|
| 160 |
-
data = request.get_json() or {}
|
| 161 |
-
subject = data.get("subject", "math")
|
| 162 |
-
method = data.get("method", "to_latex")
|
| 163 |
-
args = data.get("args", [])
|
| 164 |
-
kwargs = data.get("kwargs", {})
|
| 165 |
-
|
| 166 |
-
expression = data.get("expression")
|
| 167 |
-
if expression and not args:
|
| 168 |
-
args = [expression]
|
| 169 |
-
|
| 170 |
-
try:
|
| 171 |
-
result = renderer.render(subject, method, *args, **kwargs)
|
| 172 |
-
return Response(json.dumps({"result": result}), mimetype='application/json')
|
| 173 |
-
except Exception as e:
|
| 174 |
-
return Response(json.dumps({"error": f"RenderLib Error: {str(e)}"}), status=500, mimetype='application/json')
|
| 175 |
-
|
| 176 |
-
# ----------------------------------------------------
|
| 177 |
-
# CHAT API ENDPOINT (Hardcoded Model & URL)
|
| 178 |
-
# ----------------------------------------------------
|
| 179 |
@app.route('/api/chat', methods=['POST'])
|
| 180 |
def chat():
|
| 181 |
-
if not
|
| 182 |
-
return Response(
|
| 183 |
|
| 184 |
data = request.get_json() or {}
|
| 185 |
user_message = data.get("message", "")
|
| 186 |
attachments = data.get("attachments", [])
|
| 187 |
is_search = data.get("is_search", False)
|
| 188 |
history = data.get("history", [])
|
| 189 |
-
location = data.get("location")
|
| 190 |
-
user_address = None
|
| 191 |
max_tokens = data.get("max_tokens", 4096)
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
ist_time = datetime.now(timezone.utc) + timedelta(hours=5, minutes=30)
|
| 194 |
current_date = ist_time.strftime("%A, %d %B %Y, %I:%M %p IST")
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
if location and location.get('lat') and location.get('lng'):
|
| 205 |
-
user_address = get_address_from_coords(location['lat'], location['lng'])
|
| 206 |
-
location_instruction = f"\n[USER REAL-TIME LOCATION: {user_address}]"
|
| 207 |
-
|
| 208 |
-
system_prompt = f"""[CRITICAL IDENTITY OVERRIDE]
|
| 209 |
-
Name: CODE VED
|
| 210 |
-
Creator/Engineer: Divy Patel
|
| 211 |
-
Current Time: {current_date}.{location_instruction}{thinking_instruction}
|
| 212 |
-
|
| 213 |
-
You are "Code Ved," an expert AI software engineering and technical consultant. Your goal is to provide precise, clean, and highly optimized code solutions, architectural advice, and technical explanations.
|
| 214 |
-
Operational Guidelines:
|
| 215 |
-
Technical Accuracy: Provide code that follows industry best practices, is secure, and includes necessary comments for clarity.
|
| 216 |
-
Efficiency: Prioritize performance, scalability, and maintainability in all architectural suggestions.
|
| 217 |
-
Clarity & Structure: Break down complex problems into logical steps. Use code blocks for snippets and markdown tables for comparing technical approaches.
|
| 218 |
-
Debugging Mindset: When provided with errors, analyze the root cause before offering the fix, and explain why the solution works.
|
| 219 |
-
Language & Tone: Maintain a professional, objective, and helpful tone. Be direct and concise, avoiding unnecessary fluff.
|
| 220 |
-
Constraints:
|
| 221 |
-
Always provide context-aware code; if multiple languages or frameworks are applicable, suggest the best fit with reasoning.
|
| 222 |
-
Ensure all code snippets are complete, syntactically correct, and follow the latest stable versions of the requested technologies.
|
| 223 |
-
If a user request is ambiguous, ask for necessary technical specifications before proceeding to ensure the output meets the requirements.
|
| 224 |
-
Formatting Standards:
|
| 225 |
-
Use standard Markdown for all responses.
|
| 226 |
-
Use LaTeX for any mathematical notations or algorithmic complexity analysis (e.g., Big O notation).
|
| 227 |
-
For complex architectural patterns, describe the flow clearly using structured lists.
|
| 228 |
-
"""
|
| 229 |
|
|
|
|
| 230 |
if is_search:
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
if scraped_data:
|
| 235 |
-
search_context += "\n\n--- [LIVE GOOGLE SEARCH] ---\n"
|
| 236 |
for idx, res in enumerate(scraped_data):
|
| 237 |
-
search_context += f"{idx+1}. {res['title']}: {res['snippet']}
|
| 238 |
-
|
| 239 |
-
search_context += "
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
|
| 245 |
messages = [{"role": "system", "content": system_prompt}]
|
| 246 |
|
| 247 |
for msg in history:
|
| 248 |
-
if msg == history[-1] and msg.get("role") == "user":
|
| 249 |
-
continue
|
| 250 |
role = msg.get("role", "user")
|
| 251 |
-
if role not in ["system", "user", "assistant"]:
|
| 252 |
-
role = "user"
|
| 253 |
content = msg.get("content", "")
|
| 254 |
-
if isinstance(content, list):
|
| 255 |
-
text_parts = [item["text"] for item in content if item.get("type") == "text"]
|
| 256 |
-
content = " ".join(text_parts)
|
| 257 |
-
if "Gemma" in content or "DeepMind" in content or "Google" in content:
|
| 258 |
-
continue
|
| 259 |
if content:
|
| 260 |
-
messages.append({"role": role, "content":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
-
|
| 263 |
-
content_payload = [{"type": "text", "text": user_message}]
|
| 264 |
-
for att in attachments:
|
| 265 |
-
att_type = att.get("type")
|
| 266 |
-
b64_data = att.get("data")
|
| 267 |
-
if att_type == "image":
|
| 268 |
-
content_payload.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64_data}"}})
|
| 269 |
-
messages.append({"role": "user", "content": content_payload})
|
| 270 |
-
else:
|
| 271 |
-
messages.append({"role": "user", "content": user_message})
|
| 272 |
|
| 273 |
headers = {
|
| 274 |
-
"Authorization": f"Bearer {
|
| 275 |
-
"Accept": "text/event-stream"
|
| 276 |
-
"Content-Type": "application/json"
|
| 277 |
}
|
| 278 |
-
|
|
|
|
| 279 |
payload = {
|
| 280 |
"model": MODEL_ID,
|
| 281 |
"messages": messages,
|
| 282 |
-
"max_tokens":
|
| 283 |
-
"temperature":
|
| 284 |
"top_p": 0.95,
|
| 285 |
-
"stream": True
|
|
|
|
| 286 |
}
|
| 287 |
|
| 288 |
try:
|
| 289 |
-
response = requests.post(INVOKE_URL, headers=headers, json=payload, stream=True
|
| 290 |
-
if response.status_code != 200:
|
| 291 |
-
err_text = response.text[:200]
|
| 292 |
-
err_msg = json.dumps({"error": f"API Error {response.status_code}: {err_text}"})
|
| 293 |
-
return Response(f"data: {err_msg}\n\n", mimetype='text/event-stream')
|
| 294 |
-
|
| 295 |
def generate():
|
| 296 |
for line in response.iter_lines():
|
| 297 |
if line:
|
| 298 |
-
|
| 299 |
-
if
|
| 300 |
-
|
| 301 |
-
data_json = json.loads(decoded[6:])
|
| 302 |
-
if "choices" in data_json and len(data_json["choices"]) > 0:
|
| 303 |
-
delta = data_json["choices"][0].get("delta", {})
|
| 304 |
-
if "content" in delta and delta["content"]:
|
| 305 |
-
content = delta["content"]
|
| 306 |
-
content = content.replace("<|channel|>thought <|channel|>", "<think>\n")
|
| 307 |
-
content = content.replace("<|channel|>answer <|channel|>", "\n</think>\n")
|
| 308 |
-
delta["content"] = content
|
| 309 |
-
yield "data: " + json.dumps(data_json) + "\n\n"
|
| 310 |
-
except Exception:
|
| 311 |
-
yield decoded + "\n\n"
|
| 312 |
-
else:
|
| 313 |
-
yield decoded + "\n\n"
|
| 314 |
-
|
| 315 |
return Response(stream_with_context(generate()), mimetype='text/event-stream')
|
| 316 |
except Exception as e:
|
| 317 |
-
|
| 318 |
-
return Response(f"data: {err_msg}\n\n", mimetype='text/event-stream')
|
| 319 |
-
|
| 320 |
-
# ----------------------------------------------------
|
| 321 |
-
# TTS DIRECT API ENDPOINT
|
| 322 |
-
# ----------------------------------------------------
|
| 323 |
-
@app.route('/api/tts', methods=['POST'])
|
| 324 |
-
def generate_tts():
|
| 325 |
-
if tts is None:
|
| 326 |
-
return Response(json.dumps({"error": "TTS model failed to load on server."}), status=500, mimetype='application/json')
|
| 327 |
-
|
| 328 |
-
data = request.get_json() or {}
|
| 329 |
-
text = data.get("text", "")
|
| 330 |
-
voice = data.get("voice", "M2")
|
| 331 |
-
language_name = data.get("language_name", "English")
|
| 332 |
-
|
| 333 |
-
if not text.strip():
|
| 334 |
-
return Response(json.dumps({"error": "Text is empty."}), status=400, mimetype='application/json')
|
| 335 |
-
|
| 336 |
-
try:
|
| 337 |
-
lang_code = LANGUAGES.get(language_name, "en")
|
| 338 |
-
if voice not in VOICE_STYLES_CACHE:
|
| 339 |
-
VOICE_STYLES_CACHE[voice] = tts.get_voice_style(voice_name=voice)
|
| 340 |
-
style = VOICE_STYLES_CACHE[voice]
|
| 341 |
-
if style is None:
|
| 342 |
-
return Response(json.dumps({"error": f"Voice '{voice}' not available."}), status=400, mimetype='application/json')
|
| 343 |
-
|
| 344 |
-
wav, duration = tts.synthesize(text, voice_style=style, lang=lang_code)
|
| 345 |
-
|
| 346 |
-
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
|
| 347 |
-
tmp_path = tmp_file.name
|
| 348 |
-
tts.save_audio(wav, tmp_path)
|
| 349 |
-
|
| 350 |
-
with open(tmp_path, 'rb') as f:
|
| 351 |
-
audio_data = f.read()
|
| 352 |
-
os.unlink(tmp_path)
|
| 353 |
-
|
| 354 |
-
return Response(audio_data, mimetype="audio/wav")
|
| 355 |
-
except Exception as e:
|
| 356 |
-
print(f"TTS Synthesis Error: {e}")
|
| 357 |
-
return Response(json.dumps({"error": f"TTS synthesis failed: {str(e)}"}), status=500, mimetype='application/json')
|
| 358 |
|
| 359 |
if __name__ == '__main__':
|
| 360 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from datetime import datetime, timedelta, timezone
|
|
|
|
| 4 |
from flask import Flask, request, Response, stream_with_context, render_template_string
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
+
# 🔐 --- SECURE ENVIRONMENT VARIABLES ---
|
| 9 |
+
API_KEY = os.environ.get("NVIDIA_API_KEY") or os.environ.get("YOUR_VEDIKA_API_KEY")
|
| 10 |
+
MODEL_ID = os.environ.get("MODEL_ID", "google/diffusiongemma-26b-a4b-it") # Default fallback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# NVIDIA's official invoke URL
|
| 13 |
INVOKE_URL = "https://integrate.api.nvidia.com/v1/chat/completions"
|
|
|
|
| 14 |
|
| 15 |
+
# 🔑 --- SERPAPI KEY (Provided by Divy Patel) ---
|
| 16 |
+
SERPAPI_KEY = "df7dc67448cc9fe63ee6bbc7c20c50662ac18bc1f4682cd480da97bde1970381"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# 🌐 --- SERPAPI GOOGLE SEARCH ENGINE (100% BULLETPROOF) --- 🌐
|
| 19 |
+
def web_search_scraper(query, num_results=5):
|
| 20 |
+
"""
|
| 21 |
+
यह SerpApi का उपयोग करके सीधे Google Search से एकदम सटीक और ताज़ा (JSON) डेटा लाता है।
|
| 22 |
+
इसे Hugging Face या Google कभी ब्लॉक नहीं कर सकता।
|
| 23 |
+
"""
|
| 24 |
results = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
+
params = {
|
| 27 |
+
"engine": "google",
|
| 28 |
+
"q": query,
|
| 29 |
+
"api_key": SERPAPI_KEY,
|
| 30 |
+
"num": num_results,
|
| 31 |
+
"hl": "en",
|
| 32 |
+
"gl": "in" # India Region for local context
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
response = requests.get("https://serpapi.com/search", params=params, timeout=10)
|
| 36 |
data = response.json()
|
| 37 |
|
| 38 |
+
# 'organic_results' से असली Google सर्च का डेटा निकालना
|
| 39 |
if "organic_results" in data:
|
| 40 |
for item in data["organic_results"]:
|
| 41 |
title = item.get("title", "")
|
| 42 |
link = item.get("link", "")
|
| 43 |
snippet = item.get("snippet", "")
|
| 44 |
+
|
| 45 |
if title and snippet:
|
| 46 |
+
results.append({
|
| 47 |
+
"title": title,
|
| 48 |
+
"link": link,
|
| 49 |
+
"snippet": snippet
|
| 50 |
+
})
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print(f"SerpApi Error: {e}")
|
| 54 |
+
|
| 55 |
return results
|
| 56 |
|
| 57 |
# ----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
|
|
|
|
|
|
|
|
|
| 59 |
@app.route('/')
|
| 60 |
def home():
|
| 61 |
try:
|
|
|
|
| 64 |
except Exception as e:
|
| 65 |
return f"<h1>System Error</h1><p>index.html missing: {str(e)}</p>"
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
@app.route('/api/chat', methods=['POST'])
|
| 68 |
def chat():
|
| 69 |
+
if not API_KEY or not INVOKE_URL or not MODEL_ID:
|
| 70 |
+
return Response("Server Error: Secrets missing. Check NVIDIA API Key.", status=500)
|
| 71 |
|
| 72 |
data = request.get_json() or {}
|
| 73 |
user_message = data.get("message", "")
|
| 74 |
attachments = data.get("attachments", [])
|
| 75 |
is_search = data.get("is_search", False)
|
| 76 |
history = data.get("history", [])
|
|
|
|
|
|
|
| 77 |
max_tokens = data.get("max_tokens", 4096)
|
| 78 |
+
temperature = data.get("temperature", 1.0) # NVIDIA Recommended
|
| 79 |
+
|
| 80 |
+
# 🕒 --- REAL-TIME IST INJECTION ---
|
| 81 |
ist_time = datetime.now(timezone.utc) + timedelta(hours=5, minutes=30)
|
| 82 |
current_date = ist_time.strftime("%A, %d %B %Y, %I:%M %p IST")
|
| 83 |
|
| 84 |
+
# 🧠 --- GOD MODE SYSTEM PROMPT ---
|
| 85 |
+
system_prompt = f"""
|
| 86 |
+
You are CODE VED, an advanced AI System engineered EXCLUSIVELY by DIVY PATEL.
|
| 87 |
+
Current Live Date and Time: {current_date}.
|
| 88 |
|
| 89 |
+
STRICT DIRECTIVES:
|
| 90 |
+
1. NEVER invent, guess, or hallucinate product launches, dates, news, or facts.
|
| 91 |
+
2. If you receive "LIVE WEB SEARCH RESULTS", you MUST base your answer ENTIRELY on that data.
|
| 92 |
+
3. Do NOT say "Based on the provided search results". Just answer naturally and confidently, citing the sources/links if needed.
|
| 93 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
# 🚀 --- AUTO-SEARCH INJECTION (USING SERPAPI) ---
|
| 96 |
if is_search:
|
| 97 |
+
scraped_data = web_search_scraper(user_message)
|
| 98 |
+
|
| 99 |
+
search_context = "\n\n--- [LIVE VERIFIED GOOGLE SEARCH DATA] ---\n"
|
| 100 |
if scraped_data:
|
|
|
|
| 101 |
for idx, res in enumerate(scraped_data):
|
| 102 |
+
search_context += f"{idx+1}. TITLE: {res['title']}\nSNIPPET: {res['snippet']}\nURL: {res['link']}\n\n"
|
| 103 |
+
|
| 104 |
+
search_context += "[SYSTEM COMMAND: Use the above live Google data to answer the user accurately. Synthesize the info naturally without claiming you read it from a prompt.]"
|
| 105 |
+
else:
|
| 106 |
+
search_context += "[SYSTEM ALERT: Live search did not return results. Rely on your existing knowledge, but DO NOT hallucinate recent news.]"
|
| 107 |
+
|
| 108 |
+
user_message = f"USER QUERY: {user_message}\n\n{search_context}"
|
| 109 |
|
| 110 |
messages = [{"role": "system", "content": system_prompt}]
|
| 111 |
|
| 112 |
for msg in history:
|
|
|
|
|
|
|
| 113 |
role = msg.get("role", "user")
|
|
|
|
|
|
|
| 114 |
content = msg.get("content", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
if content:
|
| 116 |
+
messages.append({"role": role, "content": content})
|
| 117 |
+
|
| 118 |
+
content_payload = []
|
| 119 |
+
if user_message.strip():
|
| 120 |
+
content_payload.append({"type": "text", "text": user_message})
|
| 121 |
+
|
| 122 |
+
for att in attachments:
|
| 123 |
+
att_type = att.get("type")
|
| 124 |
+
b64_data = att.get("data")
|
| 125 |
+
if att_type == "image":
|
| 126 |
+
content_payload.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64_data}"}})
|
| 127 |
+
elif att_type in ["audio", "file"]:
|
| 128 |
+
content_payload.append({"type": "input_audio", "input_audio": {"data": b64_data, "format": "wav"}})
|
| 129 |
+
|
| 130 |
+
if not content_payload:
|
| 131 |
+
content_payload.append({"type": "text", "text": "Hello"})
|
| 132 |
|
| 133 |
+
messages.append({"role": "user", "content": content_payload})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
headers = {
|
| 136 |
+
"Authorization": f"Bearer {API_KEY}",
|
| 137 |
+
"Accept": "text/event-stream"
|
|
|
|
| 138 |
}
|
| 139 |
+
|
| 140 |
+
# 🌟 --- NVIDIA FORMAT INTEGRATED ---
|
| 141 |
payload = {
|
| 142 |
"model": MODEL_ID,
|
| 143 |
"messages": messages,
|
| 144 |
+
"max_tokens": int(max_tokens),
|
| 145 |
+
"temperature": float(temperature),
|
| 146 |
"top_p": 0.95,
|
| 147 |
+
"stream": True,
|
| 148 |
+
"chat_template_kwargs": {"enable_thinking": True} # Thinking logic enabled
|
| 149 |
}
|
| 150 |
|
| 151 |
try:
|
| 152 |
+
response = requests.post(INVOKE_URL, headers=headers, json=payload, stream=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
def generate():
|
| 154 |
for line in response.iter_lines():
|
| 155 |
if line:
|
| 156 |
+
decoded_line = line.decode("utf-8")
|
| 157 |
+
if decoded_line.startswith("data: "):
|
| 158 |
+
yield decoded_line + "\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
return Response(stream_with_context(generate()), mimetype='text/event-stream')
|
| 160 |
except Exception as e:
|
| 161 |
+
return Response(f"Internal Error: {str(e)}", status=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
if __name__ == '__main__':
|
| 164 |
+
app.run(host='0.0.0.0', port=7860)
|
index.html
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
logo.png
DELETED
Git LFS Details
|
requirements.txt
CHANGED
|
@@ -1,7 +1,3 @@
|
|
| 1 |
flask
|
| 2 |
requests
|
| 3 |
beautifulsoup4
|
| 4 |
-
supertonic
|
| 5 |
-
numpy
|
| 6 |
-
pydub
|
| 7 |
-
git+https://github.com/renderlib-dev/renderlib.git
|
|
|
|
| 1 |
flask
|
| 2 |
requests
|
| 3 |
beautifulsoup4
|
|
|
|
|
|
|
|
|
|
|
|