Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from transformers import CLIPProcessor, CLIPModel, BlipProcessor, BlipForConditi
|
|
5 |
import torch
|
6 |
import matplotlib.pyplot as plt
|
7 |
import numpy as np
|
|
|
8 |
|
9 |
# 初始化模型
|
10 |
clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
|
@@ -75,13 +76,10 @@ def plot_feature_differences(latent_diff):
|
|
75 |
|
76 |
# 生成详细分析
|
77 |
def generate_text_analysis(api_key, api_type, caption_a, caption_b):
|
78 |
-
import openai
|
79 |
-
|
80 |
if api_type == "DeepSeek":
|
81 |
-
from openai import OpenAI
|
82 |
client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")
|
83 |
else:
|
84 |
-
client =
|
85 |
|
86 |
response = client.chat.completions.create(
|
87 |
model="gpt-4" if api_type == "GPT" else "deepseek-chat",
|
@@ -90,7 +88,8 @@ def generate_text_analysis(api_key, api_type, caption_a, caption_b):
|
|
90 |
{"role": "user", "content": f"图片A的描述为:{caption_a}。图片B的描述为:{caption_b}。\n请对两张图片的内容和潜在特征区别进行详细分析,并输出一个简洁但富有条理的总结。"}
|
91 |
]
|
92 |
)
|
93 |
-
|
|
|
94 |
|
95 |
# 分析函数
|
96 |
def analyze_images(img_a, img_b, api_key, api_type):
|
|
|
5 |
import torch
|
6 |
import matplotlib.pyplot as plt
|
7 |
import numpy as np
|
8 |
+
from openai import OpenAI
|
9 |
|
10 |
# 初始化模型
|
11 |
clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
|
|
|
76 |
|
77 |
# 生成详细分析
|
78 |
def generate_text_analysis(api_key, api_type, caption_a, caption_b):
|
|
|
|
|
79 |
if api_type == "DeepSeek":
|
|
|
80 |
client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")
|
81 |
else:
|
82 |
+
client = OpenAI(api_key=api_key)
|
83 |
|
84 |
response = client.chat.completions.create(
|
85 |
model="gpt-4" if api_type == "GPT" else "deepseek-chat",
|
|
|
88 |
{"role": "user", "content": f"图片A的描述为:{caption_a}。图片B的描述为:{caption_b}。\n请对两张图片的内容和潜在特征区别进行详细分析,并输出一个简洁但富有条理的总结。"}
|
89 |
]
|
90 |
)
|
91 |
+
# 修复: 正确访问返回值
|
92 |
+
return response.choices[0].message.content.strip()
|
93 |
|
94 |
# 分析函数
|
95 |
def analyze_images(img_a, img_b, api_key, api_type):
|