Update app.py
Browse files
app.py
CHANGED
@@ -99,7 +99,7 @@ def update_messages_with_text(messages, generated_content):
|
|
99 |
messages.append(message_item)
|
100 |
return messages
|
101 |
|
102 |
-
def call_chatgpt_api(messages, client, max_tokens=10000, stop=None, temperature=1.
|
103 |
"""Call ChatGPT API with the given messages"""
|
104 |
try:
|
105 |
response = client.chat.completions.create(
|
@@ -254,7 +254,11 @@ def o3_chat(api_key, base_url, question, image):
|
|
254 |
messages = evaluate_single_data(data, client, executor, prompt_template, prompt_type)
|
255 |
print(messages)
|
256 |
html_output = process_message(messages)
|
257 |
-
|
|
|
|
|
|
|
|
|
258 |
|
259 |
# Gradio界面
|
260 |
def create_demo():
|
@@ -272,11 +276,37 @@ def create_demo():
|
|
272 |
|
273 |
with gr.Row():
|
274 |
output = gr.HTML(label="Response")
|
|
|
|
|
|
|
|
|
275 |
|
276 |
-
|
|
|
277 |
fn=o3_chat,
|
278 |
inputs=[api_key, base_url, question, image_input],
|
279 |
-
outputs=[output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
)
|
281 |
|
282 |
gr.Markdown("""
|
@@ -294,3 +324,4 @@ if __name__ == "__main__":
|
|
294 |
demo = create_demo()
|
295 |
demo.launch()
|
296 |
|
|
|
|
99 |
messages.append(message_item)
|
100 |
return messages
|
101 |
|
102 |
+
def call_chatgpt_api(messages, client, max_tokens=10000, stop=None, temperature=1.0):
|
103 |
"""Call ChatGPT API with the given messages"""
|
104 |
try:
|
105 |
response = client.chat.completions.create(
|
|
|
254 |
messages = evaluate_single_data(data, client, executor, prompt_template, prompt_type)
|
255 |
print(messages)
|
256 |
html_output = process_message(messages)
|
257 |
+
|
258 |
+
# 将消息转换为JSON字符串,用于下载
|
259 |
+
json_str = json.dumps(messages, ensure_ascii=False, indent=4)
|
260 |
+
|
261 |
+
return html_output, json_str
|
262 |
|
263 |
# Gradio界面
|
264 |
def create_demo():
|
|
|
276 |
|
277 |
with gr.Row():
|
278 |
output = gr.HTML(label="Response")
|
279 |
+
|
280 |
+
# 添加JSON下载功能
|
281 |
+
json_output = gr.JSON(label="Messages JSON", visible=False)
|
282 |
+
download_btn = gr.Button("Download Messages as JSON")
|
283 |
|
284 |
+
# 处理提交
|
285 |
+
result = submit_btn.click(
|
286 |
fn=o3_chat,
|
287 |
inputs=[api_key, base_url, question, image_input],
|
288 |
+
outputs=[output, json_output]
|
289 |
+
)
|
290 |
+
|
291 |
+
# 添加下载功能
|
292 |
+
download_btn.click(
|
293 |
+
fn=lambda x: x,
|
294 |
+
inputs=[json_output],
|
295 |
+
outputs=[],
|
296 |
+
_js="""
|
297 |
+
function(json_str) {
|
298 |
+
const blob = new Blob([JSON.stringify(json_str, null, 2)], { type: 'application/json' });
|
299 |
+
const url = URL.createObjectURL(blob);
|
300 |
+
const a = document.createElement('a');
|
301 |
+
a.href = url;
|
302 |
+
a.download = 'messages_' + new Date().toISOString().replace(/[:.]/g, '-') + '.json';
|
303 |
+
document.body.appendChild(a);
|
304 |
+
a.click();
|
305 |
+
document.body.removeChild(a);
|
306 |
+
URL.revokeObjectURL(url);
|
307 |
+
return [];
|
308 |
+
}
|
309 |
+
"""
|
310 |
)
|
311 |
|
312 |
gr.Markdown("""
|
|
|
324 |
demo = create_demo()
|
325 |
demo.launch()
|
326 |
|
327 |
+
|