赞
踩
传说中的GPT-4V,终于上线了,虽然还是体验阶段。不过用过 OpenAI 视觉 API 的开发者都被惊艳到了。
已经有人玩出了各种花样了,比如用AI来解说视频,其实也是如此的丝滑:
整个实现过程可以分为 7 步:
这个可以大家去玩哈
先上一个基础的示例:
先从这里拿到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.
效果还是不错滴
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。