CodeVed / app.py
Vedika
Update app.py
2fd8500 verified
Raw
History Blame
2.57 kB
import os
import logging
import time
from flask import Flask, request, Response, stream_with_context, jsonify, send_from_directory
# --- 1. एन्टरप्राइज लॉगिंग कॉन्फ़िगरेशन ---
logging.basicConfig(level=logging.INFO, format='[%(asctime)s] %(levelname)s: %(message)s')
logger = logging.getLogger("ArjunCore")
app = Flask(__name__, static_folder='.', static_url_path='')
# --- 2. कॉन्फ़िगरेशन क्लास (Environment variables से डेटा लेने के लिए) ---
class Config:
API_KEY = os.environ.get("YOUR_VEDIKA_API_KEY")
ENDPOINT = os.environ.get("BASE_URL")
MODEL_ID = os.environ.get("MODEL_ID")
# --- 3. रूट: सर्वर रन होते ही ट्रिगर होना ---
@app.route('/')
def index():
"""यह फंक्शन सुनिश्चित करता है कि जैसे ही यूज़र सर्वर पर आए, index.html लोड हो जाए।"""
logger.info("Serving index.html interface...")
return send_from_directory('.', 'index.html')
# --- 4. चैट एपीआई (LLM Proxy) ---
@app.route('/api/chat', methods=['POST'])
def chat():
"""फ्रंटएंड (Gradio/JS) से आने वाली रिक्वेस्ट को LLM तक पहुँचाना।"""
try:
data = request.json
# यहाँ आप PayloadBuilder का उपयोग करके अपना लॉजिक बढ़ा सकते हैं
logger.info("Processing chat request...")
# प्रॉक्सी लॉजिक यहाँ डालें (जैसे पिछला कोड था)
return jsonify({"status": "processing", "message": "Backend connected successfully"})
except Exception as e:
return jsonify({"error": str(e)}), 500
# --- 5. हेल्थ चेक ---
@app.route('/health')
def health():
return jsonify({"status": "Arjun Core Active", "uptime": time.time()})
# --- 6. मुख्य एक्जीक्यूशन ---
if __name__ == '__main__':
port = int(os.environ.get("PORT", 7860))
print("\n==============================================")
print(" ARJUN CORE V3 - SYSTEM ONLINE ")
print("==============================================\n")
# यह Flask का सर्वर सीधे index.html को सर्व करेगा
app.run(host='0.0.0.0', port=port, threaded=True)