112 lines
3.3 KiB
Python
112 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Oracle RAG Flask App - Lightweight web interface
|
|
Deploy to 192.168.0.147: gunicorn -w 4 app:app -b 0.0.0.0:8000
|
|
"""
|
|
|
|
from flask import Flask, request, jsonify, render_template_string
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
HTML = """
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Oracle RAG Chat</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pico/css/pico.min.css">
|
|
<style>
|
|
.response { background: #f8f9fa; padding: 1rem; border-radius: 8px; margin-top: 1rem; }
|
|
.chunk { border-left: 3px solid #0d6efd; padding-left: 1rem; margin: 0.5rem 0; }
|
|
.loading { opacity: 0.5; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main class="container">
|
|
<h1>🔮 Oracle RAG Chat</h1>
|
|
|
|
<form id="rag-form">
|
|
<label for="question">Ask a question about your documents:</label>
|
|
<input type="text" id="question" name="question" placeholder="What would you like to know?" required>
|
|
<button type="submit" id="ask-btn">Ask</button>
|
|
</form>
|
|
|
|
<div id="result"></div>
|
|
</main>
|
|
|
|
<script>
|
|
document.getElementById('rag-form').onsubmit = async (e) => {
|
|
e.preventDefault();
|
|
const btn = document.getElementById('ask-btn');
|
|
const result = document.getElementById('result');
|
|
const question = document.getElementById('question').value;
|
|
|
|
btn.disabled = true;
|
|
btn.textContent = 'Thinking...';
|
|
result.innerHTML = '<p class="loading">🔍 Searching documents...</p>';
|
|
|
|
try {
|
|
const r = await fetch('/api/ask', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({question})
|
|
});
|
|
const data = await r.json();
|
|
|
|
if (data.error) {
|
|
result.innerHTML = `<p style="color:red">❌ ${data.error}</p>`;
|
|
} else {
|
|
result.innerHTML = `<div class="response">${data.answer}</div>`;
|
|
}
|
|
} catch (err) {
|
|
result.innerHTML = `<p style="color:red">❌ Error: ${err}</p>`;
|
|
}
|
|
|
|
btn.disabled = false;
|
|
btn.textContent = 'Ask';
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
@app.route('/')
|
|
def home():
|
|
return render_template_string(HTML)
|
|
|
|
@app.route('/api/ask', methods=['POST'])
|
|
def ask():
|
|
data = request.json
|
|
question = data.get('question', '').strip()
|
|
|
|
if not question:
|
|
return jsonify({'error': 'Please provide a question'})
|
|
|
|
# TODO: Connect to Oracle RAG
|
|
return jsonify({
|
|
'question': question,
|
|
'answer': f"""🤖 **Answer**
|
|
|
|
This is a placeholder response. Configure Oracle RAG to enable full functionality.
|
|
|
|
**Your question:** {question}
|
|
|
|
**Status:** Waiting for Oracle RAG setup
|
|
|
|
To enable:
|
|
1. Run ingestion pipeline (doc_ingest_jobs)
|
|
2. Create RAG procedures (rag_ask, rag_top_chunks)
|
|
3. Set environment variables for Oracle connection
|
|
"""
|
|
})
|
|
|
|
@app.route('/api/health')
|
|
def health():
|
|
return jsonify({'status': 'ok', 'service': 'oracle-rag-flask'})
|
|
|
|
if __name__ == '__main__':
|
|
port = int(os.environ.get('PORT', 8000))
|
|
app.run(host='0.0.0.0', port=port, debug=False)
|