rahul7star commited on
Commit
e8c29a1
·
verified ·
1 Parent(s): dea3338

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py CHANGED
@@ -300,6 +300,78 @@ def call_other_space():
300
 
301
 
302
  # ========== TRAIN CONFIGURATION ==========
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  REPO_ID = "rahul7star/ohamlab"
304
  FOLDER_IN_REPO = "filter-demo/upload_20250708_041329_9c5c81"
305
  CONCEPT_SENTENCE = "ohamlab style"
 
300
 
301
 
302
  # ========== TRAIN CONFIGURATION ==========
303
+
304
+
305
+
306
+ ##checking model sample
307
+ import os
308
+ import uuid
309
+ from pathlib import Path
310
+ from huggingface_hub import hf_hub_download
311
+ from fastapi.responses import JSONResponse
312
+
313
+ # Constants
314
+ REPO_ID = "rahul7star/ohamlab"
315
+ FOLDER_IN_REPO = "filter-demo/upload_20250708_041329_9c5c81"
316
+ CONCEPT_SENTENCE = "ohamlab style"
317
+ LORA_NAME = "ohami_filter_autorun"
318
+ @app.get("/train-sample")
319
+ def fetch_images_and_generate_captions():
320
+ # Create temporary local dir
321
+ local_dir = Path(f"/tmp/{LORA_NAME}-{uuid.uuid4()}")
322
+ os.makedirs(local_dir, exist_ok=True)
323
+
324
+ # Download all files from the given subfolder
325
+ hf_hub_download(
326
+ repo_id=REPO_ID,
327
+ repo_type="dataset",
328
+ subfolder=FOLDER_IN_REPO,
329
+ local_dir=local_dir,
330
+ local_dir_use_symlinks=False,
331
+ force_download=False,
332
+ etag_timeout=10,
333
+ )
334
+
335
+ # Full path to the downloaded image folder
336
+ image_dir = local_dir / FOLDER_IN_REPO
337
+ image_paths = list(image_dir.rglob("*.jpg")) + list(image_dir.rglob("*.jpeg")) + list(image_dir.rglob("*.png"))
338
+
339
+ # If no image found, return error
340
+ if not image_paths:
341
+ return JSONResponse(status_code=400, content={"error": "No images found in the HF repo folder."})
342
+
343
+ # Generate captions for each image
344
+ captions = [
345
+ f"Autogenerated caption for {img.stem} in the {CONCEPT_SENTENCE} [trigger]" for img in image_paths
346
+ ]
347
+
348
+ return {
349
+ "local_dir": str(image_dir),
350
+ "images": [str(p) for p in image_paths],
351
+ "captions": captions
352
+ }
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
  REPO_ID = "rahul7star/ohamlab"
376
  FOLDER_IN_REPO = "filter-demo/upload_20250708_041329_9c5c81"
377
  CONCEPT_SENTENCE = "ohamlab style"