Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -56,7 +56,7 @@ def plot_feature_differences(latent_diff):
|
|
56 |
|
57 |
plt.figure(figsize=(8, 4))
|
58 |
plt.bar(indices, diff_magnitude, alpha=0.7)
|
59 |
-
plt.xlabel("Feature Index")
|
60 |
plt.ylabel("Magnitude of Difference")
|
61 |
plt.title("Feature Differences (Bar Chart)")
|
62 |
bar_chart_path = "bar_chart.png"
|
@@ -64,7 +64,7 @@ def plot_feature_differences(latent_diff):
|
|
64 |
plt.close()
|
65 |
|
66 |
plt.figure(figsize=(6, 6))
|
67 |
-
plt.pie(diff_magnitude[:10], labels=range(10), autopct="%1.1f%%", startangle=140)
|
68 |
plt.title("Top 10 Feature Differences (Pie Chart)")
|
69 |
pie_chart_path = "pie_chart.png"
|
70 |
plt.savefig(pie_chart_path)
|
@@ -120,13 +120,7 @@ def analyze_images(img_a, img_b, api_key, api_type):
|
|
120 |
}
|
121 |
|
122 |
# 批量分析
|
123 |
-
def batch_analyze(
|
124 |
-
def load_images(folder_path):
|
125 |
-
files = sorted([os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.lower().endswith(('.png', '.jpg', '.jpeg'))])
|
126 |
-
return [Image.open(f).convert("RGB") for f in files]
|
127 |
-
|
128 |
-
images_a = load_images(folder_a)
|
129 |
-
images_b = load_images(folder_b)
|
130 |
num_pairs = min(len(images_a), len(images_b))
|
131 |
|
132 |
results = []
|
@@ -143,17 +137,20 @@ with gr.Blocks() as demo:
|
|
143 |
gr.Markdown("# 批量图像对比分析工具")
|
144 |
|
145 |
api_key_input = gr.Textbox(label="API Key", placeholder="输入您的 API Key", type="password")
|
146 |
-
api_type_input = gr.
|
147 |
-
|
148 |
-
|
149 |
analyze_button = gr.Button("开始批量分析")
|
150 |
|
151 |
with gr.Row():
|
152 |
result_gallery = gr.Gallery(label="差异图像")
|
153 |
result_text_analysis = gr.Textbox(label="详细分析", interactive=False, lines=5)
|
154 |
|
155 |
-
def process_batch_analysis(
|
156 |
-
|
|
|
|
|
|
|
157 |
all_images = []
|
158 |
all_texts = []
|
159 |
|
@@ -167,7 +164,7 @@ with gr.Blocks() as demo:
|
|
167 |
|
168 |
analyze_button.click(
|
169 |
fn=process_batch_analysis,
|
170 |
-
inputs=[
|
171 |
outputs=[result_gallery, result_text_analysis]
|
172 |
)
|
173 |
|
|
|
56 |
|
57 |
plt.figure(figsize=(8, 4))
|
58 |
plt.bar(indices, diff_magnitude, alpha=0.7)
|
59 |
+
plt.xlabel("Feature Index (Latent Dimension)")
|
60 |
plt.ylabel("Magnitude of Difference")
|
61 |
plt.title("Feature Differences (Bar Chart)")
|
62 |
bar_chart_path = "bar_chart.png"
|
|
|
64 |
plt.close()
|
65 |
|
66 |
plt.figure(figsize=(6, 6))
|
67 |
+
plt.pie(diff_magnitude[:10], labels=[f"Feature {i}" for i in range(10)], autopct="%1.1f%%", startangle=140)
|
68 |
plt.title("Top 10 Feature Differences (Pie Chart)")
|
69 |
pie_chart_path = "pie_chart.png"
|
70 |
plt.savefig(pie_chart_path)
|
|
|
120 |
}
|
121 |
|
122 |
# 批量分析
|
123 |
+
def batch_analyze(images_a, images_b, api_key, api_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
num_pairs = min(len(images_a), len(images_b))
|
125 |
|
126 |
results = []
|
|
|
137 |
gr.Markdown("# 批量图像对比分析工具")
|
138 |
|
139 |
api_key_input = gr.Textbox(label="API Key", placeholder="输入您的 API Key", type="password")
|
140 |
+
api_type_input = gr.Radio(label="API 类型", choices=["GPT", "DeepSeek"], value="GPT")
|
141 |
+
images_a_input = gr.File(label="上传文件夹A图片", file_types=[".png", ".jpg", ".jpeg"], file_count="multiple")
|
142 |
+
images_b_input = gr.File(label="上传文件夹B图片", file_types=[".png", ".jpg", ".jpeg"], file_count="multiple")
|
143 |
analyze_button = gr.Button("开始批量分析")
|
144 |
|
145 |
with gr.Row():
|
146 |
result_gallery = gr.Gallery(label="差异图像")
|
147 |
result_text_analysis = gr.Textbox(label="详细分析", interactive=False, lines=5)
|
148 |
|
149 |
+
def process_batch_analysis(images_a, images_b, api_key, api_type):
|
150 |
+
images_a = [Image.open(img).convert("RGB") for img in images_a]
|
151 |
+
images_b = [Image.open(img).convert("RGB") for img in images_b]
|
152 |
+
results = batch_analyze(images_a, images_b, api_key, api_type)
|
153 |
+
|
154 |
all_images = []
|
155 |
all_texts = []
|
156 |
|
|
|
164 |
|
165 |
analyze_button.click(
|
166 |
fn=process_batch_analysis,
|
167 |
+
inputs=[images_a_input, images_b_input, api_key_input, api_type_input],
|
168 |
outputs=[result_gallery, result_text_analysis]
|
169 |
)
|
170 |
|