rahul7star commited on
Commit
dd68063
·
verified ·
1 Parent(s): 61f4a28

Update app_fast_CPU.py

Browse files
Files changed (1) hide show
  1. app_fast_CPU.py +24 -8
app_fast_CPU.py CHANGED
@@ -16,9 +16,11 @@ HF_MODEL = os.environ.get("HF_UPLOAD_REPO", "rahul7star/wan22TITV5B-image-analys
16
  # --- CPU-only upload function ---
17
  def upload_image_and_prompt_cpu(input_image, prompt_text) -> str:
18
  from datetime import datetime
19
- import tempfile, os, uuid
20
- from huggingface_hub import upload_file
21
- import shutil
 
 
22
 
23
  today_str = datetime.now().strftime("%Y-%m-%d")
24
  unique_subfolder = f"Upload-Image-{uuid.uuid4().hex[:8]}"
@@ -32,21 +34,35 @@ def upload_image_and_prompt_cpu(input_image, prompt_text) -> str:
32
  input_image.save(tmp_img.name, format="PNG")
33
  tmp_img_path = tmp_img.name
34
 
35
- # Upload image
36
- upload_file(tmp_img_path, f"{hf_folder}/input_image.png", repo_id=HF_MODEL,
37
- repo_type="model", token=os.environ.get("HUGGINGFACE_HUB_TOKEN"))
 
 
 
 
 
38
 
39
  # Save prompt as summary.txt
40
  summary_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
41
  with open(summary_file, "w", encoding="utf-8") as f:
42
  f.write(prompt_text)
43
- upload_file(summary_file, f"{hf_folder}/summary.txt", repo_id=HF_MODEL,
44
- repo_type="model", token=os.environ.get("HUGGINGFACE_HUB_TOKEN"))
45
 
 
 
 
 
 
 
 
 
 
46
  os.remove(tmp_img_path)
47
  os.remove(summary_file)
 
48
  return hf_folder
49
 
 
50
  # --- Load pipelines ---
51
  vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
52
  text_to_video_pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
 
16
  # --- CPU-only upload function ---
17
  def upload_image_and_prompt_cpu(input_image, prompt_text) -> str:
18
  from datetime import datetime
19
+ import tempfile, os, uuid, shutil
20
+ from huggingface_hub import HfApi
21
+
22
+ # Instantiate the HfApi class
23
+ api = HfApi()
24
 
25
  today_str = datetime.now().strftime("%Y-%m-%d")
26
  unique_subfolder = f"Upload-Image-{uuid.uuid4().hex[:8]}"
 
34
  input_image.save(tmp_img.name, format="PNG")
35
  tmp_img_path = tmp_img.name
36
 
37
+ # Upload image using HfApi instance
38
+ api.upload_file(
39
+ path_or_fileobj=tmp_img_path,
40
+ path_in_repo=f"{hf_folder}/input_image.png",
41
+ repo_id=HF_MODEL,
42
+ repo_type="model",
43
+ token=os.environ.get("HUGGINGFACE_HUB_TOKEN")
44
+ )
45
 
46
  # Save prompt as summary.txt
47
  summary_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
48
  with open(summary_file, "w", encoding="utf-8") as f:
49
  f.write(prompt_text)
 
 
50
 
51
+ api.upload_file(
52
+ path_or_fileobj=summary_file,
53
+ path_in_repo=f"{hf_folder}/summary.txt",
54
+ repo_id=HF_MODEL,
55
+ repo_type="model",
56
+ token=os.environ.get("HUGGINGFACE_HUB_TOKEN")
57
+ )
58
+
59
+ # Cleanup
60
  os.remove(tmp_img_path)
61
  os.remove(summary_file)
62
+
63
  return hf_folder
64
 
65
+
66
  # --- Load pipelines ---
67
  vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
68
  text_to_video_pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)