Spaces:
Running
Running
try again to display progress
Browse files
app.py
CHANGED
@@ -41,7 +41,11 @@ def create_interface():
|
|
41 |
create_btn = gr.Button("Create Private MCP Server", variant="primary")
|
42 |
create_status = gr.Markdown("")
|
43 |
|
44 |
-
def
|
|
|
|
|
|
|
|
|
45 |
"""Create private dataset and MCP server space for Apple Health data."""
|
46 |
if not oauth_token:
|
47 |
return "β Please login first!"
|
@@ -53,7 +57,8 @@ def create_interface():
|
|
53 |
return "β Please enter a project name!"
|
54 |
|
55 |
try:
|
56 |
-
progress
|
|
|
57 |
# Use the OAuth token
|
58 |
token = oauth_token.token
|
59 |
if not token:
|
@@ -69,7 +74,8 @@ def create_interface():
|
|
69 |
dataset_repo_id = f"{username}/{project_name}-data"
|
70 |
space_repo_id = f"{username}/{project_name}-mcp"
|
71 |
|
72 |
-
progress
|
|
|
73 |
# Check if repositories already exist
|
74 |
try:
|
75 |
api.repo_info(dataset_repo_id, repo_type="dataset")
|
@@ -83,7 +89,8 @@ def create_interface():
|
|
83 |
except RepositoryNotFoundError:
|
84 |
pass
|
85 |
|
86 |
-
progress
|
|
|
87 |
# Create the private dataset
|
88 |
dataset_url = create_repo(
|
89 |
repo_id=dataset_repo_id,
|
@@ -92,7 +99,8 @@ def create_interface():
|
|
92 |
token=token
|
93 |
)
|
94 |
|
95 |
-
progress
|
|
|
96 |
# Upload the export.xml file (first commit)
|
97 |
api.upload_file(
|
98 |
path_or_fileobj=file_path,
|
@@ -103,7 +111,8 @@ def create_interface():
|
|
103 |
commit_message="Initial upload: export.xml"
|
104 |
)
|
105 |
|
106 |
-
progress
|
|
|
107 |
# Create README for dataset
|
108 |
dataset_readme = f"""# Apple Health Data
|
109 |
|
@@ -128,7 +137,8 @@ This dataset is private and contains personal health information. Do not share a
|
|
128 |
token=token
|
129 |
)
|
130 |
|
131 |
-
progress
|
|
|
132 |
# Create the MCP server space
|
133 |
space_url = create_repo(
|
134 |
repo_id=space_repo_id,
|
@@ -138,7 +148,8 @@ This dataset is private and contains personal health information. Do not share a
|
|
138 |
token=token
|
139 |
)
|
140 |
|
141 |
-
progress
|
|
|
142 |
# Read MCP server code from mcp_server.py
|
143 |
with open('mcp_server.py', 'r') as f:
|
144 |
mcp_app_content = f.read()
|
@@ -152,7 +163,8 @@ This dataset is private and contains personal health information. Do not share a
|
|
152 |
token=token
|
153 |
)
|
154 |
|
155 |
-
progress
|
|
|
156 |
# Upload parser dependencies for auto-parsing functionality
|
157 |
api.upload_file(
|
158 |
path_or_fileobj="src/parser/parser.py",
|
@@ -186,7 +198,8 @@ This dataset is private and contains personal health information. Do not share a
|
|
186 |
token=token
|
187 |
)
|
188 |
|
189 |
-
progress
|
|
|
190 |
# Create requirements.txt for the space
|
191 |
requirements_content = """gradio>=5.34.0
|
192 |
huggingface-hub>=0.20.0
|
@@ -204,7 +217,8 @@ tqdm>=4.64.0
|
|
204 |
token=token
|
205 |
)
|
206 |
|
207 |
-
progress
|
|
|
208 |
# Create space variables for the dataset repo ID
|
209 |
api.add_space_variable(
|
210 |
repo_id=space_repo_id,
|
@@ -213,7 +227,8 @@ tqdm>=4.64.0
|
|
213 |
token=token
|
214 |
)
|
215 |
|
216 |
-
progress
|
|
|
217 |
# Add the token as a secret for dataset access
|
218 |
api.add_space_secret(
|
219 |
repo_id=space_repo_id,
|
@@ -222,7 +237,8 @@ tqdm>=4.64.0
|
|
222 |
token=token
|
223 |
)
|
224 |
|
225 |
-
progress
|
|
|
226 |
return f"""β
Successfully created your Private Apple Health Dataset and MCP Server!
|
227 |
|
228 |
**Private Dataset:** [{dataset_repo_id}]({dataset_url})
|
@@ -264,7 +280,7 @@ Both repositories are private and only accessible by you.
|
|
264 |
fn=lambda: gr.update(interactive=False),
|
265 |
outputs=[create_btn]
|
266 |
).then(
|
267 |
-
fn=
|
268 |
inputs=[file_input, space_name_input],
|
269 |
outputs=[create_status],
|
270 |
show_progress="full"
|
|
|
41 |
create_btn = gr.Button("Create Private MCP Server", variant="primary")
|
42 |
create_status = gr.Markdown("")
|
43 |
|
44 |
+
def create_health_landing_zone_with_progress(file_path: str, project_name: str, oauth_token: gr.OAuthToken | None, progress=gr.Progress()) -> str:
|
45 |
+
"""Wrapper function with progress tracking."""
|
46 |
+
return create_health_landing_zone(file_path, project_name, oauth_token, progress)
|
47 |
+
|
48 |
+
def create_health_landing_zone(file_path: str, project_name: str, oauth_token: gr.OAuthToken | None, progress=None) -> str:
|
49 |
"""Create private dataset and MCP server space for Apple Health data."""
|
50 |
if not oauth_token:
|
51 |
return "β Please login first!"
|
|
|
57 |
return "β Please enter a project name!"
|
58 |
|
59 |
try:
|
60 |
+
if progress:
|
61 |
+
progress(0.1, desc="π Authenticating...")
|
62 |
# Use the OAuth token
|
63 |
token = oauth_token.token
|
64 |
if not token:
|
|
|
74 |
dataset_repo_id = f"{username}/{project_name}-data"
|
75 |
space_repo_id = f"{username}/{project_name}-mcp"
|
76 |
|
77 |
+
if progress:
|
78 |
+
progress(0.2, desc="π Checking repository availability...")
|
79 |
# Check if repositories already exist
|
80 |
try:
|
81 |
api.repo_info(dataset_repo_id, repo_type="dataset")
|
|
|
89 |
except RepositoryNotFoundError:
|
90 |
pass
|
91 |
|
92 |
+
if progress:
|
93 |
+
progress(0.3, desc="π Creating private dataset...")
|
94 |
# Create the private dataset
|
95 |
dataset_url = create_repo(
|
96 |
repo_id=dataset_repo_id,
|
|
|
99 |
token=token
|
100 |
)
|
101 |
|
102 |
+
if progress:
|
103 |
+
progress(0.4, desc="π€ Uploading export.xml...")
|
104 |
# Upload the export.xml file (first commit)
|
105 |
api.upload_file(
|
106 |
path_or_fileobj=file_path,
|
|
|
111 |
commit_message="Initial upload: export.xml"
|
112 |
)
|
113 |
|
114 |
+
if progress:
|
115 |
+
progress(0.5, desc="π Creating dataset documentation...")
|
116 |
# Create README for dataset
|
117 |
dataset_readme = f"""# Apple Health Data
|
118 |
|
|
|
137 |
token=token
|
138 |
)
|
139 |
|
140 |
+
if progress:
|
141 |
+
progress(0.6, desc="π Creating MCP server space...")
|
142 |
# Create the MCP server space
|
143 |
space_url = create_repo(
|
144 |
repo_id=space_repo_id,
|
|
|
148 |
token=token
|
149 |
)
|
150 |
|
151 |
+
if progress:
|
152 |
+
progress(0.7, desc="π¦ Uploading MCP server code...")
|
153 |
# Read MCP server code from mcp_server.py
|
154 |
with open('mcp_server.py', 'r') as f:
|
155 |
mcp_app_content = f.read()
|
|
|
163 |
token=token
|
164 |
)
|
165 |
|
166 |
+
if progress:
|
167 |
+
progress(0.8, desc="π Uploading parser dependencies...")
|
168 |
# Upload parser dependencies for auto-parsing functionality
|
169 |
api.upload_file(
|
170 |
path_or_fileobj="src/parser/parser.py",
|
|
|
198 |
token=token
|
199 |
)
|
200 |
|
201 |
+
if progress:
|
202 |
+
progress(0.85, desc="π Creating requirements...")
|
203 |
# Create requirements.txt for the space
|
204 |
requirements_content = """gradio>=5.34.0
|
205 |
huggingface-hub>=0.20.0
|
|
|
217 |
token=token
|
218 |
)
|
219 |
|
220 |
+
if progress:
|
221 |
+
progress(0.9, desc="π§ Configuring environment variables...")
|
222 |
# Create space variables for the dataset repo ID
|
223 |
api.add_space_variable(
|
224 |
repo_id=space_repo_id,
|
|
|
227 |
token=token
|
228 |
)
|
229 |
|
230 |
+
if progress:
|
231 |
+
progress(0.95, desc="π Setting up secure access...")
|
232 |
# Add the token as a secret for dataset access
|
233 |
api.add_space_secret(
|
234 |
repo_id=space_repo_id,
|
|
|
237 |
token=token
|
238 |
)
|
239 |
|
240 |
+
if progress:
|
241 |
+
progress(1.0, desc="β
Complete!")
|
242 |
return f"""β
Successfully created your Private Apple Health Dataset and MCP Server!
|
243 |
|
244 |
**Private Dataset:** [{dataset_repo_id}]({dataset_url})
|
|
|
280 |
fn=lambda: gr.update(interactive=False),
|
281 |
outputs=[create_btn]
|
282 |
).then(
|
283 |
+
fn=create_health_landing_zone_with_progress,
|
284 |
inputs=[file_input, space_name_input],
|
285 |
outputs=[create_status],
|
286 |
show_progress="full"
|