danghungithp's picture
Upload 1398 files
bec48e1 verified
from flask import Blueprint, request, jsonify, render_template
import os
import pandas as pd
# import các thư viện AI cần thiết (ví dụ: groq, openai, ...)
ai_bp = Blueprint('ai', __name__)
@ai_bp.route('/analyze_gemini', methods=['POST'])
def analyze_gemini():
# Lấy prompt và các tham số từ request
user_prompt = request.json.get('prompt', '')
# Đọc dữ liệu tài chính từ file nếu cần
csv_path = 'vn-stock-analysis-app/filter_stocks.csv'
if not os.path.exists(csv_path):
return jsonify({'error': 'Không tìm thấy file filter_stocks.csv'}), 400
df = pd.read_csv(csv_path)
# Tạo prompt tổng hợp (có thể bổ sung thêm dữ liệu từ df)
full_prompt = f"Dữ liệu tài chính:\n{df.head(20).to_string()}\n\nCâu hỏi: {user_prompt}\nTrả lời bằng tiếng Việt."
# Gọi model AI (Groq, Llama, ...)
# response = groq_client.chat.completions.create(model=GROQ_MODEL, messages=[{"role": "user", "content": full_prompt}], ...)
# Kết quả mẫu (mock)
ai_result = "[Kết quả AI sẽ hiển thị ở đây]"
# Trả về kết quả
return jsonify({'result': ai_result})
# Có thể bổ sung các route AI khác (ví dụ: /analyze_vnindex_ai, /summarize_news, ...)