File size: 1,211 Bytes
94d93ca
e83d7c5
94d93ca
 
 
 
 
829f5e4
94d93ca
 
829f5e4
94d93ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829f5e4
 
94d93ca
 
 
 
 
 
 
 
 
829f5e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask, render_template, request, jsonify
from hybrid_search import ArloRAGPipeline
import threading

app = Flask(__name__)

# Initialize RAG on startup (happens once)
print("🚀 Initializing RAG Pipeline...")
rag = ArloRAGPipeline(enable_web_search=True)
rag.build()
print("✅ RAG Ready!")

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/health')
def health():
    return jsonify({"status": "healthy", "rag_ready": rag.vectorstore is not None})

@app.route('/query', methods=['POST'])
def query():
    question = request.json.get('question', '')
    if not question:
        return jsonify({"error": "No question provided"}), 400
    
    # Capture RAG output
    import io
    import sys
    old_stdout = sys.stdout
    sys.stdout = buffer = io.StringIO()
    
    rag.query(question)
    
    output = buffer.getvalue()
    sys.stdout = old_stdout
    
    # Extract answer
    if "💡 Answer:" in output:
        answer = output.split("💡 Answer:")[1].strip()
    else:
        answer = output
    
    return jsonify({
        "question": question,
        "answer": answer
    })

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)