idlebg commited on
Commit
2cb234f
1 Parent(s): 1427b84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -7,7 +7,7 @@ from huggingface_hub import login, HfApi, HfFolder
7
  from PIL import Image
8
  import os
9
  from datetime import datetime
10
-
11
 
12
  # Get your Hugging Face API token
13
  folder = HfFolder()
@@ -33,27 +33,31 @@ pipe2.enable_xformers_memory_efficient_attention()
33
 
34
  def save_image_to_hf_space(image_np, image_name):
35
  # Name of your Hugging Face repo
36
- repo_name = "FFusion/FFusionXL-SDXL-DEMO"
37
 
38
  # Convert the numpy array to an image
39
  image = Image.fromarray(image_np.astype('uint8'))
40
 
41
  # Append a timestamp to the filename
42
  timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
43
- image_name_with_timestamp = f"{image_name}-{timestamp}"
44
 
45
  # Save the image locally
46
- image_path = f"./{image_name_with_timestamp}.png"
47
- image.save(image_path)
48
 
49
  # Upload the image to your Hugging Face repo
50
  api.upload_file(
51
  token=token,
52
- path_or_fileobj=image_path,
53
  repo_id=repo_name,
54
- filename=image_name_with_timestamp,
55
  )
56
 
 
 
 
 
57
 
58
  def genie (prompt, negative_prompt, scale, steps, seed):
59
  torch.cuda.empty_cache()
@@ -65,8 +69,8 @@ def genie (prompt, negative_prompt, scale, steps, seed):
65
  refined_image_np = np.array(refined_images[0])
66
 
67
  # Save the generated images to Hugging Face Spaces
68
- # save_image_to_hf_space(int_image_np, "int_image")
69
- # save_image_to_hf_space(refined_image_np, "refined_image")
70
 
71
  return int_image_np, refined_image_np
72
 
 
7
  from PIL import Image
8
  import os
9
  from datetime import datetime
10
+ import shutil
11
 
12
  # Get your Hugging Face API token
13
  folder = HfFolder()
 
33
 
34
  def save_image_to_hf_space(image_np, image_name):
35
  # Name of your Hugging Face repo
36
+ repo_name = "FFusion/FF2"
37
 
38
  # Convert the numpy array to an image
39
  image = Image.fromarray(image_np.astype('uint8'))
40
 
41
  # Append a timestamp to the filename
42
  timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
43
+ image_name_with_timestamp = f"{image_name}-{timestamp}.png"
44
 
45
  # Save the image locally
46
+ local_image_path = f"./{image_name_with_timestamp}"
47
+ image.save(local_image_path)
48
 
49
  # Upload the image to your Hugging Face repo
50
  api.upload_file(
51
  token=token,
52
+ path_or_fileobj=local_image_path,
53
  repo_id=repo_name,
54
+ path_in_repo=image_name_with_timestamp # The path where the image will be stored in the repository
55
  )
56
 
57
+ # Save the image to the persistent storage
58
+ persistent_storage_path = f"/data/{image_name_with_timestamp}"
59
+ shutil.copy(local_image_path, persistent_storage_path)
60
+
61
 
62
  def genie (prompt, negative_prompt, scale, steps, seed):
63
  torch.cuda.empty_cache()
 
69
  refined_image_np = np.array(refined_images[0])
70
 
71
  # Save the generated images to Hugging Face Spaces
72
+ save_image_to_hf_space(int_image_np, "int_image")
73
+ save_image_to_hf_space(refined_image_np, "refined_image")
74
 
75
  return int_image_np, refined_image_np
76