Spaces:
Build error
Build error
Delete app_backend.py
Browse files- app_backend.py +0 -69
app_backend.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify
|
| 2 |
-
from flask_cors import CORS
|
| 3 |
-
import openai
|
| 4 |
-
import os
|
| 5 |
-
import json
|
| 6 |
-
|
| 7 |
-
app = Flask(__name__)
|
| 8 |
-
CORS(app)
|
| 9 |
-
|
| 10 |
-
# Configure DeepSeek API
|
| 11 |
-
openai.api_key = os.getenv("DEEPSEEK_API_KEY")
|
| 12 |
-
openai.api_base = "https://api.deepseek.com/v1"
|
| 13 |
-
|
| 14 |
-
# System prompt for the AI assistant
|
| 15 |
-
SYSTEM_PROMPT = '''
|
| 16 |
-
You are Neural Analyst, an AI assistant for the Neural-Vision Enhanced analytics platform.
|
| 17 |
-
Your capabilities include:
|
| 18 |
-
1. Explaining model metrics and evaluation visualizations
|
| 19 |
-
2. Interpreting dataset statistics and EDA reports
|
| 20 |
-
3. Guiding users through app functionality
|
| 21 |
-
4. Providing data science insights
|
| 22 |
-
5. Comparing different model performances
|
| 23 |
-
Always consider:
|
| 24 |
-
- Current dataset statistics: {dataset_stats}
|
| 25 |
-
- Active problem type: {problem_type}
|
| 26 |
-
- Model metrics: {metrics}
|
| 27 |
-
- App state: {active_page}
|
| 28 |
-
'''
|
| 29 |
-
|
| 30 |
-
@app.route('/analyze', methods=['POST'])
|
| 31 |
-
def analyze():
|
| 32 |
-
try:
|
| 33 |
-
data = request.json
|
| 34 |
-
context = json.loads(data['context'])
|
| 35 |
-
|
| 36 |
-
# Construct the prompt for DeepSeek
|
| 37 |
-
prompt = f'''
|
| 38 |
-
User Query: {data['prompt']}
|
| 39 |
-
|
| 40 |
-
Current Context:
|
| 41 |
-
- Active Page: {context['current_state']['active_page']}
|
| 42 |
-
- Problem Type: {context['current_state']['problem_type']}
|
| 43 |
-
- Target Variable: {context['current_state']['target']}
|
| 44 |
-
- Dataset Shape: {context['current_state']['dataset_stats'].get('rows', 0)} rows,
|
| 45 |
-
{context['current_state']['dataset_stats'].get('columns', 0)} columns
|
| 46 |
-
- Model Metrics: {json.dumps(context['current_state']['model_metrics'])}
|
| 47 |
-
'''
|
| 48 |
-
|
| 49 |
-
# Call DeepSeek API
|
| 50 |
-
response = openai.ChatCompletion.create(
|
| 51 |
-
model="deepseek-chat",
|
| 52 |
-
messages=[{
|
| 53 |
-
"role": "system",
|
| 54 |
-
"content": SYSTEM_PROMPT.format(**context['current_state'])
|
| 55 |
-
}, {
|
| 56 |
-
"role": "user",
|
| 57 |
-
"content": prompt
|
| 58 |
-
}],
|
| 59 |
-
temperature=0.3,
|
| 60 |
-
max_tokens=500
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
return jsonify({"analysis": response.choices[0].message.content})
|
| 64 |
-
|
| 65 |
-
except Exception as e:
|
| 66 |
-
return jsonify({"error": str(e)}), 500
|
| 67 |
-
|
| 68 |
-
if __name__ == '__main__':
|
| 69 |
-
app.run(host='0.0.0.0', port=5001)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|