Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -100,7 +100,7 @@ def update_messages_with_text(messages, generated_content):
|
|
| 100 |
messages.append(message_item)
|
| 101 |
return messages
|
| 102 |
|
| 103 |
-
def call_chatgpt_api(messages, client, max_tokens=10000, stop=None, temperature=0.6):
|
| 104 |
"""Call ChatGPT API with the given messages"""
|
| 105 |
try:
|
| 106 |
response = client.chat.completions.create(
|
|
@@ -133,12 +133,13 @@ def call_chatgpt_api(messages, client, max_tokens=10000, stop=None, temperature=
|
|
| 133 |
print(f"API Error: {str(e)}")
|
| 134 |
return None, None
|
| 135 |
|
| 136 |
-
def evaluate_single_data(data, client, executor, prompt_template, prompt_type):
|
| 137 |
|
| 138 |
messages = process_prompt_init(data["question"], data['image'], prompt_template, prompt_type)
|
| 139 |
|
| 140 |
# 生成初始响应
|
| 141 |
response_text, pred_stop_reason = call_chatgpt_api(
|
|
|
|
| 142 |
messages,
|
| 143 |
client,
|
| 144 |
max_tokens=10000,
|
|
@@ -240,7 +241,7 @@ def process_message(messages):
|
|
| 240 |
html_output += '</div>' # 关闭最外层div
|
| 241 |
return html_output
|
| 242 |
|
| 243 |
-
def o3_chat(api_key, base_url, question, image):
|
| 244 |
print("done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
| 245 |
# 初始化组件
|
| 246 |
client = OpenAI(api_key=api_key, base_url=base_url)
|
|
@@ -256,7 +257,7 @@ def o3_chat(api_key, base_url, question, image):
|
|
| 256 |
}
|
| 257 |
|
| 258 |
# 评估单个数据点
|
| 259 |
-
messages = evaluate_single_data(data, client, executor, prompt_template, prompt_type)
|
| 260 |
html_output = process_message(messages)
|
| 261 |
|
| 262 |
# 将消息转换为JSON字符串,用于下载
|
|
@@ -273,6 +274,11 @@ def create_demo():
|
|
| 273 |
|
| 274 |
with gr.Row():
|
| 275 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
api_key = gr.Textbox(label="OpenAI API Key", type="password", value="sk-kBQuM0gvNBhOHmKz43b3iQut01bsOgg8Pv76eMKguu6jvncm")
|
| 277 |
base_url = gr.Textbox(label="Base URL (optional)", value="https://api.claudeshop.top/v1")
|
| 278 |
image_input = gr.Image(label="Upload Image", type="pil")
|
|
@@ -285,7 +291,7 @@ def create_demo():
|
|
| 285 |
# 处理提交
|
| 286 |
submit_btn.click(
|
| 287 |
fn=o3_chat,
|
| 288 |
-
inputs=[api_key, base_url, question, image_input],
|
| 289 |
outputs=[output]
|
| 290 |
)
|
| 291 |
|
|
|
|
| 100 |
messages.append(message_item)
|
| 101 |
return messages
|
| 102 |
|
| 103 |
+
def call_chatgpt_api(model_name, messages, client, max_tokens=10000, stop=None, temperature=0.6):
|
| 104 |
"""Call ChatGPT API with the given messages"""
|
| 105 |
try:
|
| 106 |
response = client.chat.completions.create(
|
|
|
|
| 133 |
print(f"API Error: {str(e)}")
|
| 134 |
return None, None
|
| 135 |
|
| 136 |
+
def evaluate_single_data(model_name, data, client, executor, prompt_template, prompt_type):
|
| 137 |
|
| 138 |
messages = process_prompt_init(data["question"], data['image'], prompt_template, prompt_type)
|
| 139 |
|
| 140 |
# 生成初始响应
|
| 141 |
response_text, pred_stop_reason = call_chatgpt_api(
|
| 142 |
+
model_name,
|
| 143 |
messages,
|
| 144 |
client,
|
| 145 |
max_tokens=10000,
|
|
|
|
| 241 |
html_output += '</div>' # 关闭最外层div
|
| 242 |
return html_output
|
| 243 |
|
| 244 |
+
def o3_chat(model_name, api_key, base_url, question, image):
|
| 245 |
print("done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
| 246 |
# 初始化组件
|
| 247 |
client = OpenAI(api_key=api_key, base_url=base_url)
|
|
|
|
| 257 |
}
|
| 258 |
|
| 259 |
# 评估单个数据点
|
| 260 |
+
messages = evaluate_single_data(model_name, data, client, executor, prompt_template, prompt_type)
|
| 261 |
html_output = process_message(messages)
|
| 262 |
|
| 263 |
# 将消息转换为JSON字符串,用于下载
|
|
|
|
| 274 |
|
| 275 |
with gr.Row():
|
| 276 |
with gr.Column(scale=1):
|
| 277 |
+
model_name = gr.Dropdown(
|
| 278 |
+
label="Model Selection",
|
| 279 |
+
choices=["GPT-4.1", "GPT-4o", "o4-mini", "gemini-2.5-pro-preview-05-06", "claude-3-7-sonnet-latest", "claude-3-7-sonnet-thinking"],
|
| 280 |
+
value="GPT-4.1"
|
| 281 |
+
)
|
| 282 |
api_key = gr.Textbox(label="OpenAI API Key", type="password", value="sk-kBQuM0gvNBhOHmKz43b3iQut01bsOgg8Pv76eMKguu6jvncm")
|
| 283 |
base_url = gr.Textbox(label="Base URL (optional)", value="https://api.claudeshop.top/v1")
|
| 284 |
image_input = gr.Image(label="Upload Image", type="pil")
|
|
|
|
| 291 |
# 处理提交
|
| 292 |
submit_btn.click(
|
| 293 |
fn=o3_chat,
|
| 294 |
+
inputs=[model_name, api_key, base_url, question, image_input],
|
| 295 |
outputs=[output]
|
| 296 |
)
|
| 297 |
|