laichaoyi commited on
Commit
bace505
·
verified ·
1 Parent(s): 40c50e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -85,6 +85,30 @@ def save_metadata_to_file(image_input, prompt, neg_prompt, model, loras, seed, s
85
  return txt_file, gr.Info(f"Đang tải file metadata.txt...", duration=2)
86
 
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  def handle_automatic1111(prompt_info):
89
  prompt = prompt_info.full_prompt
90
  negative_prompt = prompt_info.full_negative_prompt if prompt_info.full_negative_prompt else "N/A"
 
85
  return txt_file, gr.Info(f"Đang tải file metadata.txt...", duration=2)
86
 
87
 
88
+
89
+ def read_image_metadata(image_path):
90
+ try:
91
+ if not image_path:
92
+ raise ValueError("Không có ảnh được tải lên.")
93
+
94
+ with Image.open(image_path) as img:
95
+ prompt_info = parser_manager.parse(img)
96
+
97
+ if not prompt_info:
98
+ raise ValueError("Không thể đọc thông tin từ ảnh.")
99
+
100
+ # Kiểm tra loại generator
101
+ if prompt_info.generator == "AUTOMATIC1111":
102
+ return handle_automatic1111(prompt_info)
103
+ elif prompt_info.generator == "ComfyUI":
104
+ return handle_comfyui(prompt_info)
105
+ else:
106
+ raise ValueError("Loại generator không được hỗ trợ.")
107
+
108
+ except Exception as e:
109
+ print(f"Lỗi khi xử lý ảnh: {str(e)}")
110
+ return "Không tìm thấy thông tin!", "", "", "", "", "", "", ""
111
+
112
  def handle_automatic1111(prompt_info):
113
  prompt = prompt_info.full_prompt
114
  negative_prompt = prompt_info.full_negative_prompt if prompt_info.full_negative_prompt else "N/A"