rahul7star commited on
Commit
eb2059f
·
verified ·
1 Parent(s): 740d79f

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +27 -15
app1.py CHANGED
@@ -39,29 +39,42 @@ def load_model():
39
  return tok, model
40
 
41
 
42
- def upload_to_hf(image_path, summary_text):
43
- """Upload image + summary text to Hugging Face model repo"""
44
- unique_folder = f"image_{uuid.uuid4().hex[:8]}"
45
- logging.info(f"Creating new HF folder: {unique_folder} in repo {HF_MODEL}")
46
-
47
- # Upload image
48
- img_filename = os.path.basename(image_path)
49
- img_hf_path = f"{unique_folder}/{img_filename}"
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  upload_file(
51
- path_or_fileobj=image_path,
52
- path_in_repo=img_hf_path,
53
  repo_id=HF_MODEL,
54
  repo_type="model",
55
  token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
56
  )
57
- logging.info(f"✅ Uploaded image to HF: {img_hf_path}")
58
 
59
- # Upload summary text
60
  summary_file = "/tmp/summary.txt"
61
  with open(summary_file, "w", encoding="utf-8") as f:
62
  f.write(summary_text)
63
 
64
- summary_hf_path = f"{unique_folder}/summary.txt"
65
  upload_file(
66
  path_or_fileobj=summary_file,
67
  path_in_repo=summary_hf_path,
@@ -71,8 +84,7 @@ def upload_to_hf(image_path, summary_text):
71
  )
72
  logging.info(f"✅ Uploaded summary to HF: {summary_hf_path}")
73
 
74
- return f"Uploaded to Hugging Face under {unique_folder}"
75
-
76
 
77
  def caption_image(image, custom_prompt=None):
78
  """Generate caption + upload image+caption to HF"""
 
39
  return tok, model
40
 
41
 
42
+ import os
43
+ import uuid
44
+ import logging
45
+ from datetime import datetime
46
+ from huggingface_hub import HfApi, upload_file
47
+
48
+ def upload_to_hf(video_path, summary_text):
49
+ api = HfApi()
50
+
51
+ # Create a date-based folder (YYYY-MM-DD)
52
+ today_str = datetime.now().strftime("%Y-%m-%d")
53
+ date_folder = today_str
54
+
55
+ # Generate a unique subfolder for this upload
56
+ unique_subfolder = f"Apple-Imge-Text-upload_{uuid.uuid4().hex[:8]}"
57
+ hf_folder = f"{date_folder}/{unique_subfolder}"
58
+ logging.info(f"Uploading files to HF folder: {hf_folder} in repo {HF_MODEL}")
59
+
60
+ # Upload video
61
+ video_filename = os.path.basename(video_path)
62
+ video_hf_path = f"{hf_folder}/{video_filename}"
63
  upload_file(
64
+ path_or_fileobj=video_path,
65
+ path_in_repo=video_hf_path,
66
  repo_id=HF_MODEL,
67
  repo_type="model",
68
  token=os.environ.get("HUGGINGFACE_HUB_TOKEN"),
69
  )
70
+ logging.info(f"✅ Uploaded video to HF: {video_hf_path}")
71
 
72
+ # Upload summary.txt
73
  summary_file = "/tmp/summary.txt"
74
  with open(summary_file, "w", encoding="utf-8") as f:
75
  f.write(summary_text)
76
 
77
+ summary_hf_path = f"{hf_folder}/summary.txt"
78
  upload_file(
79
  path_or_fileobj=summary_file,
80
  path_in_repo=summary_hf_path,
 
84
  )
85
  logging.info(f"✅ Uploaded summary to HF: {summary_hf_path}")
86
 
87
+ return hf_folder
 
88
 
89
  def caption_image(image, custom_prompt=None):
90
  """Generate caption + upload image+caption to HF"""