import gradio as gr import openai import os from openai import OpenAI client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) # 设置OpenAI的API密钥 # 将用户的输入数据以正确的格式提交给模型 def get_response(text, image1, image2, image3, image4): response = client.chat.completions.create( model="gpt-4-vision-preview", messages=[{ "role": "user", "content": [ {"type": "text","text": f'{text}'}, {"type": "image_url","image_url": {"url": f'{image1}'},}, {"type": "image_url","image_url": {"url": f'{image2}'},}, {"type": "image_url","image_url": {"url": f'{image3}'},}, {"type": "image_url","image_url": {"url": f'{image4}'},}, ],}], temperature=0, # 设置temperature为0以获得稳定结果 max_tokens=600 ) return response.choices[0].message.content # gradio UI iface = gr.Interface( fn=get_response, inputs=["text", "text", "text", "text", "text"], outputs="text" ) iface.launch(share=True,debug=True) #share=True,debug=True