Update app.py
Browse files
app.py
CHANGED
@@ -405,15 +405,23 @@ def process_message(messages):
|
|
405 |
html_output += '</div>' # 关闭最外层div
|
406 |
return html_output
|
407 |
|
408 |
-
def o3_chat(model_name, api_key, base_url, question, image):
|
409 |
print("done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
410 |
# 初始化组件
|
411 |
-
client = AzureOpenAI(
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
)
|
416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
executor = PythonExecutor()
|
418 |
|
419 |
prompt_template = json.load(open("./prompt_template_vis.json", "r", encoding="utf-8"))
|
@@ -448,6 +456,7 @@ def create_demo():
|
|
448 |
choices=["gpt-4.1"],
|
449 |
value="gpt-4.1"
|
450 |
)
|
|
|
451 |
api_key = gr.Textbox(label="OpenAI API Key (optional)", type="password", value=os.getenv("AZURE_OPENAI_API_KEY"))
|
452 |
base_url = gr.Textbox(label="Base URL (optional)", value=os.getenv("AZURE_OPENAI_ENDPOINT"))
|
453 |
image_input = gr.Image(label="Upload Image", type="pil")
|
@@ -479,7 +488,7 @@ def create_demo():
|
|
479 |
|
480 |
submit_btn.click(
|
481 |
fn=handle_submit,
|
482 |
-
inputs=[model_name, api_key, base_url, question, image_input],
|
483 |
outputs=[output, extracted_images, extracted_json, current_images, current_json]
|
484 |
)
|
485 |
|
|
|
405 |
html_output += '</div>' # 关闭最外层div
|
406 |
return html_output
|
407 |
|
408 |
+
def o3_chat(model_name, client_type, api_key, base_url, question, image):
|
409 |
print("done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
410 |
# 初始化组件
|
411 |
+
# client = AzureOpenAI(
|
412 |
+
# api_key=os.getenv("AZURE_OPENAI_API_KEY"), # 从环境变量读取
|
413 |
+
# api_version="2025-04-01-preview", # 使用最新API版本
|
414 |
+
# azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT") # 终结点URL
|
415 |
+
# )
|
416 |
+
|
417 |
+
if client_type == "Azure":
|
418 |
+
client = AzureOpenAI(
|
419 |
+
api_key=api_key, # 从环境变量读取
|
420 |
+
api_version="2025-04-01-preview", # 使用最新API版本
|
421 |
+
azure_endpoint=base_url # 终结点URL
|
422 |
+
)
|
423 |
+
else:
|
424 |
+
client = OpenAI(api_key=api_key, base_url=base_url)
|
425 |
executor = PythonExecutor()
|
426 |
|
427 |
prompt_template = json.load(open("./prompt_template_vis.json", "r", encoding="utf-8"))
|
|
|
456 |
choices=["gpt-4.1"],
|
457 |
value="gpt-4.1"
|
458 |
)
|
459 |
+
client_type = gr.Dropdown(label="Client Type Selection", choices=["Azure", "OpenAI"], value="Azure")
|
460 |
api_key = gr.Textbox(label="OpenAI API Key (optional)", type="password", value=os.getenv("AZURE_OPENAI_API_KEY"))
|
461 |
base_url = gr.Textbox(label="Base URL (optional)", value=os.getenv("AZURE_OPENAI_ENDPOINT"))
|
462 |
image_input = gr.Image(label="Upload Image", type="pil")
|
|
|
488 |
|
489 |
submit_btn.click(
|
490 |
fn=handle_submit,
|
491 |
+
inputs=[model_name, client_type, api_key, base_url, question, image_input],
|
492 |
outputs=[output, extracted_images, extracted_json, current_images, current_json]
|
493 |
)
|
494 |
|