OpenAI GPT-4视觉API可以玩了,GPT4V,gpt-4-vision-preview,chatgpt
传说中的GPT-4V,终于上线了,虽然还是体验阶段。不过用过 OpenAI 视觉 API 的开发者都被惊艳到了。
已经有人玩出了各种花样了,比如用AI来解说视频,其实也是如此的丝滑:
整个实现过程可以分为 7 步:
- 提取视频帧;
- 构建描述提示;
- 发送 GPT 请求;
- 制作语音解说提示;
- 生成语音解说脚本;
- 将脚本转换为音频;
- 将音频与视频结合。
这个可以大家去玩哈
先上一个基础的示例:
1、首先需要拿到openai的key和url,
项目github地址:https://github.com/xing61/xiaoyi-robot
-
第1步:用手机号登录智增增,获取复制出key和url,地址:https://gpt.zhizengzeng.com/#/login
-
第2步:编写代码。注意配置的base_url是:
https://api.zhizengzeng.com/v1
2、开始撸python代码:(其它语言类似)
import os
import openai
import requests
import time
import json
import time
API_SECRET_KEY = "你的智增增的key";
BASE_URL = "https://api.zhizengzeng.com/v1/" #智增增的base_url
from openai import OpenAI
# gpt4v
def gpt4v(query):
client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
resp = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": query},
{
"type": "image_url",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
],
}
],
max_tokens=300,
)
print(resp)
print(resp.choices[0].message.content)
if __name__ == '__main__':
gpt4v("What are in these images? Is there any difference between them?");
上面的代码传了一个图片给openai,然后让他指出图片里面有什么,以及刁难的问到:这几个图片的差异是什么(其实我只传了一个图片)
图片如下:
于是我们看到返回:
I'm sorry, but I can only view one image at a time. The image you've provided is a beautiful landscape scene. It features a wooden boardwalk or path leading through a lush green meadow with tall grass on both sides. The sky is partly cloudy with a rich blue color and some gentle white clouds, suggesting a pleasant day. The scenery is tranquil and might be a nature reserve or park. There are no people or animals visible in the image. If you have another image for comparison, please provide it separately.
效果还是不错滴
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...