muhammadsalmanalfaridzi commited on
Commit
3a0a1c5
β€’
1 Parent(s): 235ace7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -38,19 +38,25 @@ def remove_background_bria(input_path):
38
 
39
  # Fungsi untuk memproses gambar menggunakan prompt
40
  def text_to_image(prompt):
41
- os.makedirs("generated_images", exist_ok=True)
42
- image = sd_model(prompt).images[0] # Use sd_model instead of pipe
 
43
  image_path = f"generated_images/{prompt.replace(' ', '_')}.png"
44
- image.save(image_path)
45
- return image, image_path
46
-
47
- def text_image_to_image(image, prompt):
48
- os.makedirs("generated_images", exist_ok=True)
49
- # Convert input image to PIL Image for processing
50
- modified_image = sd_model(prompt, init_image=image, strength=0.75).images[0] # Use sd_model here too
 
 
 
 
 
51
  image_path = f"generated_images/{prompt.replace(' ', '_')}_modified.png"
52
- modified_image.save(image_path)
53
- return modified_image, image_path
54
 
55
  def get_bounding_box_with_threshold(image, threshold):
56
  # Convert image to numpy array
@@ -509,10 +515,19 @@ def process_images(input_files, bg_method='rembg', watermark_path=None, canvas_s
509
 
510
  # Create a zip file of processed images
511
  with zipfile.ZipFile(output_zip_path, 'w') as zipf:
512
- for processed_img in processed_images:
513
- zipf.write(processed_img)
514
-
515
- return processed_images, output_zip_path
 
 
 
 
 
 
 
 
 
516
 
517
  def gradio_interface(input_files, bg_method, watermark, canvas_size, output_format, bg_choice, custom_color, num_workers):
518
  progress = gr.Progress()
 
38
 
39
  # Fungsi untuk memproses gambar menggunakan prompt
40
  def text_to_image(prompt):
41
+ os.makedirs("generated_images", exist_ok=True) # Ensure the directory exists
42
+ image = sd_model(prompt).images[0] # Generate image using the model
43
+ # Create a sanitized filename by replacing spaces with underscores
44
  image_path = f"generated_images/{prompt.replace(' ', '_')}.png"
45
+ image.save(image_path) # Save the generated image
46
+ return image, image_path # Return the image and its path
47
+
48
+ # Function to modify an image based on a text prompt
49
+ def text_image_to_image(input_image, prompt):
50
+ os.makedirs("generated_images", exist_ok=True) # Ensure the directory exists
51
+ # Convert input image to PIL Image if necessary
52
+ if not isinstance(input_image, Image.Image):
53
+ input_image = Image.open(input_image) # Load image from path if given as string
54
+ # Generate modified image using the model with the input image and prompt
55
+ modified_image = sd_model(prompt, init_image=input_image, strength=0.75).images[0]
56
+ # Create a sanitized filename for the modified image
57
  image_path = f"generated_images/{prompt.replace(' ', '_')}_modified.png"
58
+ modified_image.save(image_path) # Save the modified image
59
+ return modified_image, image_path # Return the modified image and its path
60
 
61
  def get_bounding_box_with_threshold(image, threshold):
62
  # Convert image to numpy array
 
515
 
516
  # Create a zip file of processed images
517
  with zipfile.ZipFile(output_zip_path, 'w') as zipf:
518
+ for file_info in processed_images:
519
+ file_path, _ = file_info
520
+ zipf.write(file_path, os.path.basename(file_path))
521
+
522
+ with open(os.path.join(output_folder, 'process_log.json'), 'w') as log_file:
523
+ json.dump(all_logs, log_file, indent=4)
524
+ print("Comprehensive log saved to", os.path.join(output_folder, 'process_log.json'))
525
+
526
+ end_time = time.time()
527
+ processing_time = end_time - start_time
528
+ print(f"Processing time: {processing_time} seconds")
529
+
530
+ return original_images, processed_images, output_zip_path, processing_time
531
 
532
  def gradio_interface(input_files, bg_method, watermark, canvas_size, output_format, bg_choice, custom_color, num_workers):
533
  progress = gr.Progress()