跳至主要内容

SceneXplain

SceneXplain 是一款通过 SceneXplain 工具访问的图像字幕服务。

要使用此工具,您需要创建一个帐户并从网站获取您的 API 令牌。然后您可以实例化该工具。

import os

os.environ["SCENEX_API_KEY"] = "<YOUR_API_KEY>"
from langchain.agents import load_tools

tools = load_tools(["sceneXplain"])
API 参考:load_tools

或者直接实例化该工具。

from langchain_community.tools import SceneXplainTool

tool = SceneXplainTool()
API 参考:SceneXplainTool

在代理中使用

该工具可以在任何 LangChain 代理中使用,如下所示

from langchain.agents import initialize_agent
from langchain.memory import ConversationBufferMemory
from langchain_openai import OpenAI

llm = OpenAI(temperature=0)
memory = ConversationBufferMemory(memory_key="chat_history")
agent = initialize_agent(
tools, llm, memory=memory, agent="conversational-react-description", verbose=True
)
output = agent.run(
input=(
"What is in this image https://storage.googleapis.com/causal-diffusion.appspot.com/imagePrompts%2F0rw369i5h9t%2Foriginal.png. "
"Is it movie or a game? If it is a movie, what is the name of the movie?"
)
)

print(output)


> Entering new AgentExecutor chain...

Thought: Do I need to use a tool? Yes
Action: Image Explainer
Action Input: https://storage.googleapis.com/causal-diffusion.appspot.com/imagePrompts%2F0rw369i5h9t%2Foriginal.png
Observation: In a charmingly whimsical scene, a young girl is seen braving the rain alongside her furry companion, the lovable Totoro. The two are depicted standing on a bustling street corner, where they are sheltered from the rain by a bright yellow umbrella. The girl, dressed in a cheerful yellow frock, holds onto the umbrella with both hands while gazing up at Totoro with an expression of wonder and delight.

Totoro, meanwhile, stands tall and proud beside his young friend, holding his own umbrella aloft to protect them both from the downpour. His furry body is rendered in rich shades of grey and white, while his large ears and wide eyes lend him an endearing charm.

In the background of the scene, a street sign can be seen jutting out from the pavement amidst a flurry of raindrops. A sign with Chinese characters adorns its surface, adding to the sense of cultural diversity and intrigue. Despite the dreary weather, there is an undeniable sense of joy and camaraderie in this heartwarming image.
Thought: Do I need to use a tool? No
AI: This image appears to be a still from the 1988 Japanese animated fantasy film My Neighbor Totoro. The film follows two young girls, Satsuki and Mei, as they explore the countryside and befriend the magical forest spirits, including the titular character Totoro.

> Finished chain.
This image appears to be a still from the 1988 Japanese animated fantasy film My Neighbor Totoro. The film follows two young girls, Satsuki and Mei, as they explore the countryside and befriend the magical forest spirits, including the titular character Totoro.

此页面是否有帮助?


您也可以留下详细的反馈 在 GitHub 上.