OpenAI GPT-4视觉API可以玩了,GPT4V,gpt-4-vision-preview,chatgpt

传说中的GPT-4V,终于上线了,虽然还是体验阶段。不过用过 OpenAI 视觉 API 的开发者都被惊艳到了。

已经有人玩出了各种花样了,比如用AI来解说视频,其实也是如此的丝滑:

整个实现过程可以分为 7 步:

  • 提取视频帧;
  • 构建描述提示;
  • 发送 GPT 请求;
  • 制作语音解说提示;
  • 生成语音解说脚本;
  • 将脚本转换为音频;
  • 将音频与视频结合。

这个可以大家去玩哈

先上一个基础的示例:

先从这里拿到key:https://github.com/xing61/xiaoyi-robot

import os

import openai
import requests
import time
import json
import time

API_SECRET_KEY = "你的智增增的key";
BASE_URL = "https://flag.smarttrot.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.

效果还是不错滴

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值