NitinBot001 commited on
Commit
0209330
·
verified ·
1 Parent(s): 08bafde

Update medicine.py

Browse files
Files changed (1) hide show
  1. medicine.py +9 -7
medicine.py CHANGED
@@ -86,16 +86,17 @@ def get_context_from_file(filename: str) -> str | None:
86
  def handle_query():
87
  """
88
  Main API endpoint to handle user queries.
89
- Accepts form data with 'query' (required) and 'file' (optional image upload).
90
  """
91
  # 1. Get and validate the request data
92
- form_data = request.form
93
- query = request.json.get('main_query')
94
- if not query and not form_data:
 
 
 
 
95
  return jsonify({"error": "Missing 'query' in request"}), 400
96
-
97
- user_query = query or form_data.get('query')
98
- medicine_topic = None
99
 
100
  # 2. Handle File Upload (if provided)
101
  if 'file' in request.files:
@@ -124,6 +125,7 @@ def handle_query():
124
  return jsonify({"error": f"Invalid file type. Allowed types: {', '.join(ALLOWED_EXTENSIONS)}"}), 400
125
 
126
  # 3. Handle Text-Only Input (or use the topic identified from the image)
 
127
  if not medicine_topic:
128
  print("No image provided. Identifying topic from text query...")
129
  try:
 
86
  def handle_query():
87
  """
88
  Main API endpoint to handle user queries.
89
+ Accepts JSON data with 'query' (required) and 'file' (optional image upload).
90
  """
91
  # 1. Get and validate the request data
92
+ if not request.is_json:
93
+ return jsonify({"error": "Request must be in JSON format with 'query' field"}), 400
94
+
95
+ data = request.get_json()
96
+ user_query = data.get('main_query')
97
+
98
+ if not user_query:
99
  return jsonify({"error": "Missing 'query' in request"}), 400
 
 
 
100
 
101
  # 2. Handle File Upload (if provided)
102
  if 'file' in request.files:
 
125
  return jsonify({"error": f"Invalid file type. Allowed types: {', '.join(ALLOWED_EXTENSIONS)}"}), 400
126
 
127
  # 3. Handle Text-Only Input (or use the topic identified from the image)
128
+ medicine_topic = None
129
  if not medicine_topic:
130
  print("No image provided. Identifying topic from text query...")
131
  try: