Swetha commited on
Commit
f9d30dc
·
1 Parent(s): 61a4f8f

server updated

Browse files
Files changed (1) hide show
  1. server.py +23 -23
server.py CHANGED
@@ -178,18 +178,18 @@ except Exception:
178
  # ==============================
179
  # Configuration / DB Connection
180
  # ==============================
181
-
182
  # ==============================
183
  # Configuration / DB Connection
184
  # ==============================
185
-
186
  #IS_HUGGING_FACE = os.environ.get('HUGGINGFACE_SPACES') == 'true' or os.environ.get('SPACE_ID') is not None
187
 
188
  if IS_HUGGING_FACE:
189
  # Hugging Face Spaces configuration
190
  DEFAULT_SQL_SERVER = "pykara-sqlserver.c5aosm6ie5j3.eu-north-1.rds.amazonaws.com,1433"
191
  DEFAULT_SQL_DB = "PyMatch"
192
- DEFAULT_SQL_TRUSTED = "no" # Use SQL authentication on Hugging Face
193
  else:
194
  # Local development configuration
195
  DEFAULT_SQL_SERVER = "localhost\\SQLEXPRESS"
@@ -204,7 +204,7 @@ SQL_USER = os.getenv("PYMATCH_SQL_USER", "")
204
  SQL_PASSWORD = os.getenv("PYMATCH_SQL_PASSWORD", "")
205
  SQL_PORT = os.getenv("PYMATCH_SQL_PORT", "")
206
  SQL_ENCRYPT = os.getenv("PYMATCH_SQL_ENCRYPT", "no").lower().strip()
207
- SQL_TRUSTCERT = os.getenv("PYMATCH_SQL_TRUSTCERT", "yes").lower().strip()
208
 
209
  PROGRESS_TBL = os.getenv("PYMATCH_PROGRESS_TABLE", "LLMGeneratedQuestions")
210
  DEFAULT_N_QUESTIONS = int(os.getenv("PYMATCH_DEFAULT_N_QUESTIONS", "20"))
@@ -1094,35 +1094,35 @@ def submit_answers():
1094
  try:
1095
  conn = get_db_connection()
1096
  cur = conn.cursor()
1097
-
1098
  table_name = "Marriage"
1099
  placeholders = ", ".join(["?"] * (len(role_fields["marriage"]) + 1))
1100
  query = f"INSERT INTO {table_name} (user_id, {', '.join(role_fields['marriage'])}) VALUES ({placeholders})"
1101
-
1102
  values = [user_id]
1103
  for f in role_fields["marriage"]:
1104
  val = data.get(f)
1105
-
1106
  # Handle list values (multiselect)
1107
  if isinstance(val, list):
1108
  val = ", ".join([str(v) for v in val])
1109
-
1110
  # Convert to string or None
1111
  if val is None:
1112
  val = None
1113
  else:
1114
  val = str(val)
1115
-
1116
  values.append(val)
1117
 
1118
  print(f"DEBUG: Executing query: {query}") # Debug log
1119
  print(f"DEBUG: Values: {values}") # Debug log
1120
-
1121
  cur.execute(query, values)
1122
  conn.commit()
1123
-
1124
  return jsonify({"message": "Marriage record added successfully."}), 201
1125
-
1126
  except pyodbc.Error as e:
1127
  print(f"Database Error: {e}") # Detailed error logging
1128
  return jsonify({"error": f"Database error: {str(e)}"}), 500
@@ -1130,9 +1130,9 @@ def submit_answers():
1130
  print(f"Unexpected Error: {e}") # Detailed error logging
1131
  return jsonify({"error": f"Unexpected error: {str(e)}"}), 500
1132
  finally:
1133
- try:
1134
  conn.close()
1135
- except:
1136
  pass
1137
 
1138
  @app.get("/api/expectation-questions")
@@ -1736,7 +1736,7 @@ def choose_themes(sess: SessionState, k: int) -> List[str]:
1736
  else:
1737
  # fallback: use generic themes
1738
  fallback_themes = [
1739
- "communication style", "conflict resolution", "decision making",
1740
  "problem solving", "team collaboration", "personal values",
1741
  "work habits", "social interaction", "stress management",
1742
  "goal setting", "time management", "relationship dynamics"
@@ -1933,29 +1933,29 @@ def get_marriage_profile(user_id: int):
1933
  try:
1934
  conn = get_db_connection()
1935
  cur = conn.cursor()
1936
-
1937
  cur.execute("""
1938
- SELECT * FROM Marriage
1939
  WHERE user_id = ?
1940
  ORDER BY created_at DESC
1941
  """, (user_id,))
1942
-
1943
  row = cur.fetchone()
1944
  if row is None:
1945
  return jsonify({"error": "Marriage profile not found"}), 404
1946
-
1947
  # Convert row to dict
1948
  profile = row_to_dict(cur, row)
1949
-
1950
  return jsonify(profile), 200
1951
-
1952
  except Exception as e:
1953
  print(f"Error fetching marriage profile: {e}")
1954
  return jsonify({"error": str(e)}), 500
1955
  finally:
1956
- try:
1957
  conn.close()
1958
- except:
1959
  pass
1960
 
1961
 
 
178
  # ==============================
179
  # Configuration / DB Connection
180
  # ==============================
181
+
182
  # ==============================
183
  # Configuration / DB Connection
184
  # ==============================
185
+
186
  #IS_HUGGING_FACE = os.environ.get('HUGGINGFACE_SPACES') == 'true' or os.environ.get('SPACE_ID') is not None
187
 
188
  if IS_HUGGING_FACE:
189
  # Hugging Face Spaces configuration
190
  DEFAULT_SQL_SERVER = "pykara-sqlserver.c5aosm6ie5j3.eu-north-1.rds.amazonaws.com,1433"
191
  DEFAULT_SQL_DB = "PyMatch"
192
+ DEFAULT_SQL_TRUSTED = "yes" # Use SQL authentication on Hugging Face
193
  else:
194
  # Local development configuration
195
  DEFAULT_SQL_SERVER = "localhost\\SQLEXPRESS"
 
204
  SQL_PASSWORD = os.getenv("PYMATCH_SQL_PASSWORD", "")
205
  SQL_PORT = os.getenv("PYMATCH_SQL_PORT", "")
206
  SQL_ENCRYPT = os.getenv("PYMATCH_SQL_ENCRYPT", "no").lower().strip()
207
+ SQL_TRUSTCERT = os.getenv("PYMATCH_SQL_TRUST_CERT", "yes").lower().strip()
208
 
209
  PROGRESS_TBL = os.getenv("PYMATCH_PROGRESS_TABLE", "LLMGeneratedQuestions")
210
  DEFAULT_N_QUESTIONS = int(os.getenv("PYMATCH_DEFAULT_N_QUESTIONS", "20"))
 
1094
  try:
1095
  conn = get_db_connection()
1096
  cur = conn.cursor()
1097
+
1098
  table_name = "Marriage"
1099
  placeholders = ", ".join(["?"] * (len(role_fields["marriage"]) + 1))
1100
  query = f"INSERT INTO {table_name} (user_id, {', '.join(role_fields['marriage'])}) VALUES ({placeholders})"
1101
+
1102
  values = [user_id]
1103
  for f in role_fields["marriage"]:
1104
  val = data.get(f)
1105
+
1106
  # Handle list values (multiselect)
1107
  if isinstance(val, list):
1108
  val = ", ".join([str(v) for v in val])
1109
+
1110
  # Convert to string or None
1111
  if val is None:
1112
  val = None
1113
  else:
1114
  val = str(val)
1115
+
1116
  values.append(val)
1117
 
1118
  print(f"DEBUG: Executing query: {query}") # Debug log
1119
  print(f"DEBUG: Values: {values}") # Debug log
1120
+
1121
  cur.execute(query, values)
1122
  conn.commit()
1123
+
1124
  return jsonify({"message": "Marriage record added successfully."}), 201
1125
+
1126
  except pyodbc.Error as e:
1127
  print(f"Database Error: {e}") # Detailed error logging
1128
  return jsonify({"error": f"Database error: {str(e)}"}), 500
 
1130
  print(f"Unexpected Error: {e}") # Detailed error logging
1131
  return jsonify({"error": f"Unexpected error: {str(e)}"}), 500
1132
  finally:
1133
+ try:
1134
  conn.close()
1135
+ except:
1136
  pass
1137
 
1138
  @app.get("/api/expectation-questions")
 
1736
  else:
1737
  # fallback: use generic themes
1738
  fallback_themes = [
1739
+ "communication style", "conflict resolution", "decision making",
1740
  "problem solving", "team collaboration", "personal values",
1741
  "work habits", "social interaction", "stress management",
1742
  "goal setting", "time management", "relationship dynamics"
 
1933
  try:
1934
  conn = get_db_connection()
1935
  cur = conn.cursor()
1936
+
1937
  cur.execute("""
1938
+ SELECT * FROM Marriage
1939
  WHERE user_id = ?
1940
  ORDER BY created_at DESC
1941
  """, (user_id,))
1942
+
1943
  row = cur.fetchone()
1944
  if row is None:
1945
  return jsonify({"error": "Marriage profile not found"}), 404
1946
+
1947
  # Convert row to dict
1948
  profile = row_to_dict(cur, row)
1949
+
1950
  return jsonify(profile), 200
1951
+
1952
  except Exception as e:
1953
  print(f"Error fetching marriage profile: {e}")
1954
  return jsonify({"error": str(e)}), 500
1955
  finally:
1956
+ try:
1957
  conn.close()
1958
+ except:
1959
  pass
1960
 
1961