xiaoming32236046
commited on
Commit
•
cf63d8e
1
Parent(s):
bb339fe
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
from openai import OpenAI
|
5 |
+
#client = OpenAI(api_key="")
|
6 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
7 |
+
# 设置OpenAI的API密钥
|
8 |
+
|
9 |
+
# 将用户的输入数据以正确的格式提交给模型
|
10 |
+
def get_response(text, image1, image2, image3, image4):
|
11 |
+
response = client.chat.completions.create(
|
12 |
+
model="gpt-4-vision-preview",
|
13 |
+
messages=[{
|
14 |
+
"role": "user",
|
15 |
+
"content": [
|
16 |
+
{"type": "text","text": f'{text}'},
|
17 |
+
{"type": "image_url","image_url": {"url": f'{image1}'},},
|
18 |
+
{"type": "image_url","image_url": {"url": f'{image2}'},},
|
19 |
+
{"type": "image_url","image_url": {"url": f'{image3}'},},
|
20 |
+
{"type": "image_url","image_url": {"url": f'{image4}'},},
|
21 |
+
],}],
|
22 |
+
temperature=0, # 设置temperature为0以获得稳定结果
|
23 |
+
max_tokens=600
|
24 |
+
)
|
25 |
+
return response.choices[0].message.content
|
26 |
+
|
27 |
+
# gradio UI
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=get_response,
|
30 |
+
inputs=["text", "text", "text", "text", "text"],
|
31 |
+
outputs="text"
|
32 |
+
)
|
33 |
+
|
34 |
+
iface.launch()
|
35 |
+
#share=True,debug=True
|