Adieee5 commited on
Commit
02387c5
·
verified ·
1 Parent(s): 80eca78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
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
- data = request.json
70
- query = data.get('message', '').strip()
 
 
 
 
 
71
 
72
- if not query:
73
- return jsonify({"error": "No message provided."}), 400
 
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)}") # For debugging
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 ===