当前位置:   article > 正文

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

gpt-4v api

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

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

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

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

这个可以大家去玩哈

先上一个基础的示例:

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

  1. import os
  2. import openai
  3. import requests
  4. import time
  5. import json
  6. import time
  7. API_SECRET_KEY = "你的智增增的key";
  8. BASE_URL = "https://flag.smarttrot.com/v1/" #智增增的base_url
  9. from openai import OpenAI
  10. # gpt4v
  11. def gpt4v(query):
  12. client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
  13. resp = client.chat.completions.create(
  14. model="gpt-4-vision-preview",
  15. messages=[
  16. {
  17. "role": "user",
  18. "content": [
  19. {"type": "text", "text": query},
  20. {
  21. "type": "image_url",
  22. "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",
  23. },
  24. ],
  25. }
  26. ],
  27. max_tokens=300,
  28. )
  29. print(resp)
  30. print(resp.choices[0].message.content)
  31. if __name__ == '__main__':
  32. 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.

效果还是不错滴

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/600001
推荐阅读
相关标签
  

闽ICP备14008679号