fffiloni commited on
Commit
fa511ce
Β·
verified Β·
1 Parent(s): a2df110

Upload 5 files

Browse files
Files changed (3) hide show
  1. CHANGELOG.md +8 -0
  2. README.md +5 -0
  3. app.py +110 -5
CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
  # Changelog
2
 
 
 
 
 
 
 
 
 
3
  ## V3
4
 
5
  - Added Phase 3 Pi smoke test.
 
1
  # Changelog
2
 
3
+ ## V5
4
+
5
+ - Added Phase 5: `model_id` β†’ model metadata analysis β†’ Pi-adapted Gradio template β†’ private Space β†’ live API validation.
6
+ - Added `model_analysis.json` in the Bucket run folder.
7
+ - Increased default Job timeout to 30 minutes for model Space builds.
8
+
9
+ # Changelog
10
+
11
  ## V3
12
 
13
  - Added Phase 3 Pi smoke test.
README.md CHANGED
@@ -135,3 +135,8 @@ The target Space remains private by default. Success is only declared after the
135
  ## Phase 4
136
 
137
  Phase 4 asks Pi to follow the HF Spaces Agent Quickstart gist and use the `hf` CLI inside an HF Job to create/upload a private Space. The wrapper independently validates the live Gradio API before reporting success.
 
 
 
 
 
 
135
  ## Phase 4
136
 
137
  Phase 4 asks Pi to follow the HF Spaces Agent Quickstart gist and use the `hf` CLI inside an HF Job to create/upload a private Space. The wrapper independently validates the live Gradio API before reporting success.
138
+
139
+
140
+ ## V5
141
+
142
+ Adds Phase 5: model-card analysis for simple Transformers text pipeline models. Recommended first test: `sshleifer/tiny-gpt2`. The Space remains private and success is still gated by wrapper-owned live API validation.
app.py CHANGED
@@ -13,6 +13,7 @@ from src.jobs import (
13
  launch_create_private_space_job,
14
  launch_hello_job,
15
  launch_pi_gist_recipe_job,
 
16
  launch_pi_space_smoke_job,
17
  )
18
  from src.runs import make_run_id, validate_run_id
@@ -20,7 +21,7 @@ from src.security import redact
20
 
21
 
22
  APP_DESCRIPTION = f"""
23
- # Agentic Space Factory β€” V4 Pi Gist Recipe
24
 
25
  This version validates the two critical foundations:
26
 
@@ -29,6 +30,7 @@ Phase 1: HF OAuth β†’ HF Job β†’ mounted private Bucket β†’ run state/events/rep
29
  Phase 2: HF OAuth β†’ HF Job β†’ private target Space β†’ file upload β†’ live Gradio API validation β†’ Bucket report
30
  Phase 3: HF OAuth β†’ HF Job β†’ Pi modifies app.py β†’ private target Space β†’ live API validation β†’ Pi traces
31
  Phase 4: HF OAuth β†’ HF Job β†’ Pi reads gist β†’ uses hf CLI β†’ private Space β†’ wrapper live API validation
 
32
  ```
33
 
34
  Configured bucket: `{settings.bucket_uri}`
@@ -75,6 +77,41 @@ def propose_gist_run_id() -> str:
75
  return make_run_id("gist")
76
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  def launch_pi_gist_job_ui(
79
  requested_run_id: str,
80
  target_space_name: str,
@@ -207,6 +244,74 @@ def build_demo() -> gr.Blocks:
207
  login_status = gr.Markdown()
208
  demo.load(fn=get_login_status, inputs=None, outputs=login_status)
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  with gr.Tab("Phase 4 β€” Pi gist recipe"):
211
  gr.Markdown(
212
  """
@@ -424,11 +529,11 @@ It will fail safely if the target Space already exists, to avoid overwriting use
424
  """
425
  ## Next increments
426
 
427
- After Phase 4 passes, the next step is Phase 5:
428
 
429
- 1. analyze a real model card,
430
- 2. choose a small template,
431
- 3. let Pi apply the same gist-style loop,
432
  4. keep the wrapper-owned live API validation gate.
433
  """
434
  )
 
13
  launch_create_private_space_job,
14
  launch_hello_job,
15
  launch_pi_gist_recipe_job,
16
+ launch_pi_model_card_job,
17
  launch_pi_space_smoke_job,
18
  )
19
  from src.runs import make_run_id, validate_run_id
 
21
 
22
 
23
  APP_DESCRIPTION = f"""
24
+ # Agentic Space Factory β€” V5 Model Card
25
 
26
  This version validates the two critical foundations:
27
 
 
30
  Phase 2: HF OAuth β†’ HF Job β†’ private target Space β†’ file upload β†’ live Gradio API validation β†’ Bucket report
31
  Phase 3: HF OAuth β†’ HF Job β†’ Pi modifies app.py β†’ private target Space β†’ live API validation β†’ Pi traces
32
  Phase 4: HF OAuth β†’ HF Job β†’ Pi reads gist β†’ uses hf CLI β†’ private Space β†’ wrapper live API validation
33
+ Phase 5: HF OAuth β†’ HF Job β†’ model-card analysis β†’ Pi adapts template β†’ private model Space β†’ live API validation
34
  ```
35
 
36
  Configured bucket: `{settings.bucket_uri}`
 
77
  return make_run_id("gist")
78
 
79
 
80
+ def propose_model_run_id() -> str:
81
+ return make_run_id("model")
82
+
83
+
84
+
85
+ def launch_pi_model_card_job_ui(
86
+ requested_run_id: str,
87
+ model_id: str,
88
+ target_space_name: str,
89
+ pi_model: str,
90
+ profile: gr.OAuthProfile | None,
91
+ oauth_token: gr.OAuthToken | None,
92
+ ) -> tuple[str, str, str, str, str, str]:
93
+ username = _profile_username(profile)
94
+ token = _token_value(oauth_token)
95
+ if not username or not token:
96
+ raise gr.Error("Please sign in with Hugging Face first. OAuth profile/token is missing.")
97
+
98
+ run_id = validate_run_id(requested_run_id or propose_model_run_id())
99
+ result = launch_pi_model_card_job(
100
+ token=token,
101
+ username=username,
102
+ target_slug=target_space_name,
103
+ model_id=model_id,
104
+ pi_model=pi_model,
105
+ run_id=run_id,
106
+ )
107
+
108
+ job_url = result.get("job_url") or ""
109
+ target_space = result.get("target_space") or ""
110
+ target_url = result.get("target_space_url") or ""
111
+ summary = json.dumps(result, indent=2)
112
+ return run_id, result["job_id"], job_url, target_space, target_url, summary
113
+
114
+
115
  def launch_pi_gist_job_ui(
116
  requested_run_id: str,
117
  target_space_name: str,
 
244
  login_status = gr.Markdown()
245
  demo.load(fn=get_login_status, inputs=None, outputs=login_status)
246
 
247
+
248
+ with gr.Tab("Phase 5 β€” Model card β†’ private Space"):
249
+ gr.Markdown(
250
+ """
251
+ This phase starts from a real Hugging Face `model_id`. The Job fetches model metadata/model card, gates to a small set of simple Transformers text-pipeline tasks, prepares a Gradio template, asks Pi to adapt the app, then creates a **private** target Space and validates the live API.
252
+
253
+ Recommended first test model: `sshleifer/tiny-gpt2`.
254
+
255
+ This phase is intentionally limited: simple text models only, private Space only, no ZeroGPU yet, no gated-model secret injection yet.
256
+ """
257
+ )
258
+ with gr.Row():
259
+ model_run_id_box = gr.Textbox(label="Run ID", value=propose_model_run_id, interactive=True)
260
+ new_model_run_btn = gr.Button("Generate new run id")
261
+ new_model_run_btn.click(fn=propose_model_run_id, inputs=None, outputs=model_run_id_box)
262
+
263
+ model_id_box = gr.Textbox(
264
+ label="Model ID",
265
+ value="sshleifer/tiny-gpt2",
266
+ info="Use a small public model for the first test. Phase 5 supports simple Transformers text pipeline tasks only.",
267
+ )
268
+ model_target_space_name = gr.Textbox(
269
+ label="Target Space name",
270
+ placeholder="e.g. space-factory-model-tiny-gpt2-v1",
271
+ info="Use a new name. The Space is created under your own username and is private.",
272
+ )
273
+ model_pi_model_box = gr.Textbox(
274
+ label="Pi model",
275
+ value="moonshotai/Kimi-K2.5",
276
+ info="Model used by Pi through Hugging Face Inference Providers.",
277
+ )
278
+ launch_model_btn = gr.Button("Generate model Space", variant="primary")
279
+
280
+ phase5_job_id_box = gr.Textbox(label="Job ID", interactive=True)
281
+ phase5_job_url_box = gr.Textbox(label="Job URL", interactive=False)
282
+ phase5_target_space_box = gr.Textbox(label="Target Space", interactive=False)
283
+ phase5_target_url_box = gr.Textbox(label="Target Space URL", interactive=False)
284
+ phase5_launch_result = gr.Code(label="Launch result", language="json")
285
+
286
+ launch_model_btn.click(
287
+ fn=launch_pi_model_card_job_ui,
288
+ inputs=[model_run_id_box, model_id_box, model_target_space_name, model_pi_model_box],
289
+ outputs=[
290
+ model_run_id_box,
291
+ phase5_job_id_box,
292
+ phase5_job_url_box,
293
+ phase5_target_space_box,
294
+ phase5_target_url_box,
295
+ phase5_launch_result,
296
+ ],
297
+ )
298
+
299
+ phase5_refresh_btn = gr.Button("Refresh Phase 5 run status")
300
+ with gr.Tab("Phase 5 state"):
301
+ phase5_state_code = gr.Code(label="state.json", language="json")
302
+ with gr.Tab("Phase 5 events"):
303
+ phase5_events_code = gr.Code(label="events.jsonl", language="json")
304
+ with gr.Tab("Phase 5 report"):
305
+ phase5_report_md = gr.Markdown()
306
+ with gr.Tab("Phase 5 job"):
307
+ phase5_job_code = gr.Code(label="Job status/logs", language="json")
308
+
309
+ phase5_refresh_btn.click(
310
+ fn=refresh_run_ui,
311
+ inputs=[model_run_id_box, phase5_job_id_box],
312
+ outputs=[phase5_state_code, phase5_events_code, phase5_report_md, phase5_job_code],
313
+ )
314
+
315
  with gr.Tab("Phase 4 β€” Pi gist recipe"):
316
  gr.Markdown(
317
  """
 
529
  """
530
  ## Next increments
531
 
532
+ After Phase 5 passes, the next step is Phase 6:
533
 
534
+ 1. add a ZeroGPU Diffusers template,
535
+ 2. improve model compatibility gating,
536
+ 3. support richer validation by output type,
537
  4. keep the wrapper-owned live API validation gate.
538
  """
539
  )