grlll commited on
Commit
818246d
·
1 Parent(s): b103a10

remove the need for a oauth token

Browse files
Files changed (1) hide show
  1. mcp_server.py +6 -17
mcp_server.py CHANGED
@@ -99,7 +99,7 @@ def check_and_parse_if_needed():
99
  print(f"Error during local parsing: {str(e)}")
100
  raise
101
 
102
- def get_db_connection(token=None):
103
  """Get a connection to the SQLite database."""
104
  if DATA_REPO and IS_HF_SPACE:
105
  # Running in HF Spaces - download from private dataset
@@ -108,7 +108,7 @@ def get_db_connection(token=None):
108
  repo_id=DATA_REPO,
109
  filename="health_data.db",
110
  repo_type="dataset",
111
- token=token or HF_TOKEN
112
  )
113
  return sqlite3.connect(db_path)
114
  except Exception as e:
@@ -119,7 +119,7 @@ def get_db_connection(token=None):
119
  raise FileNotFoundError(f"Database file not found: {LOCAL_DB_PATH}. Try restarting the server to trigger auto-parsing.")
120
  return sqlite3.connect(LOCAL_DB_PATH)
121
 
122
- def execute_sql_query(sql_query, hf_token=None):
123
  """Execute any SQL query on the Apple Health SQLite database.
124
 
125
  Args:
@@ -133,7 +133,7 @@ def execute_sql_query(sql_query, hf_token=None):
133
  return "Error: Empty SQL query provided"
134
 
135
  try:
136
- conn = get_db_connection(token=hf_token)
137
 
138
  # Execute the query
139
  result = pd.read_sql_query(sql_query, conn)
@@ -163,18 +163,7 @@ with gr.Blocks(title="Apple Health MCP Server") as demo:
163
  with gr.Tab("SQL Query Interface"):
164
  gr.Markdown("### Execute SQL Queries")
165
  gr.Markdown("Enter any SQL query to execute against your Apple Health SQLite database.")
166
-
167
- # Only show token input if running in HF Spaces
168
- if IS_HF_SPACE and DATA_REPO:
169
- hf_token_input = gr.Textbox(
170
- label="Hugging Face Token",
171
- placeholder="hf_...",
172
- type="password",
173
- info="Your HF token to access the private dataset. Get it from https://huggingface.co/settings/tokens"
174
- )
175
- else:
176
- hf_token_input = gr.Textbox(visible=False, value=None)
177
-
178
  sql_input = gr.Textbox(
179
  label="SQL Query",
180
  placeholder="SELECT * FROM activity_summaries LIMIT 10;",
@@ -203,7 +192,7 @@ with gr.Blocks(title="Apple Health MCP Server") as demo:
203
 
204
  query_btn.click(
205
  fn=execute_sql_query,
206
- inputs=[sql_input, hf_token_input],
207
  outputs=output
208
  )
209
 
 
99
  print(f"Error during local parsing: {str(e)}")
100
  raise
101
 
102
+ def get_db_connection():
103
  """Get a connection to the SQLite database."""
104
  if DATA_REPO and IS_HF_SPACE:
105
  # Running in HF Spaces - download from private dataset
 
108
  repo_id=DATA_REPO,
109
  filename="health_data.db",
110
  repo_type="dataset",
111
+ token=HF_TOKEN
112
  )
113
  return sqlite3.connect(db_path)
114
  except Exception as e:
 
119
  raise FileNotFoundError(f"Database file not found: {LOCAL_DB_PATH}. Try restarting the server to trigger auto-parsing.")
120
  return sqlite3.connect(LOCAL_DB_PATH)
121
 
122
+ def execute_sql_query(sql_query):
123
  """Execute any SQL query on the Apple Health SQLite database.
124
 
125
  Args:
 
133
  return "Error: Empty SQL query provided"
134
 
135
  try:
136
+ conn = get_db_connection()
137
 
138
  # Execute the query
139
  result = pd.read_sql_query(sql_query, conn)
 
163
  with gr.Tab("SQL Query Interface"):
164
  gr.Markdown("### Execute SQL Queries")
165
  gr.Markdown("Enter any SQL query to execute against your Apple Health SQLite database.")
166
+
 
 
 
 
 
 
 
 
 
 
 
167
  sql_input = gr.Textbox(
168
  label="SQL Query",
169
  placeholder="SELECT * FROM activity_summaries LIMIT 10;",
 
192
 
193
  query_btn.click(
194
  fn=execute_sql_query,
195
+ inputs=[sql_input],
196
  outputs=output
197
  )
198