File size: 1,126 Bytes
cf63d8e 3e58957 cf63d8e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
import openai
import os
from openai import OpenAI
client = OpenAI(api_key="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")
#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 |