Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -62,21 +62,32 @@ CORS(app)
|
|
62 |
def index():
|
63 |
return render_template("index.html") # Make sure chat.html exists
|
64 |
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# === Step 8: API Route - Change to match what your frontend expects ===
|
67 |
@app.route('/api/chat', methods=['POST'])
|
68 |
def chat():
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
|
|
74 |
|
75 |
-
try:
|
76 |
response = qa_chain.run(query)
|
|
|
|
|
77 |
return jsonify({"response": response})
|
78 |
except Exception as e:
|
79 |
-
print(f"Error: {str(e)}")
|
80 |
return jsonify({"response": f"Sorry, I encountered an error: {str(e)}"}), 500
|
81 |
|
82 |
# === Step 9: Run the App ===
|
|
|
62 |
def index():
|
63 |
return render_template("index.html") # Make sure chat.html exists
|
64 |
|
65 |
+
@app.route('/api/test', methods=['GET', 'POST'])
|
66 |
+
def test():
|
67 |
+
print("Test endpoint reached")
|
68 |
+
return jsonify({"status": "API is working!", "message": "Connection successful"})
|
69 |
|
70 |
# === Step 8: API Route - Change to match what your frontend expects ===
|
71 |
@app.route('/api/chat', methods=['POST'])
|
72 |
def chat():
|
73 |
+
print("Received request to /api/chat")
|
74 |
+
try:
|
75 |
+
data = request.json
|
76 |
+
print(f"Request data: {data}")
|
77 |
+
|
78 |
+
query = data.get('message', '').strip()
|
79 |
+
print(f"Query: {query}")
|
80 |
|
81 |
+
if not query:
|
82 |
+
print("No message provided")
|
83 |
+
return jsonify({"error": "No message provided."}), 400
|
84 |
|
|
|
85 |
response = qa_chain.run(query)
|
86 |
+
print(f"Generated response: {response}")
|
87 |
+
|
88 |
return jsonify({"response": response})
|
89 |
except Exception as e:
|
90 |
+
print(f"Error in chat endpoint: {str(e)}")
|
91 |
return jsonify({"response": f"Sorry, I encountered an error: {str(e)}"}), 500
|
92 |
|
93 |
# === Step 9: Run the App ===
|