Spaces:
Runtime error
Runtime error
Commit ·
017b074
1
Parent(s): 6528d41
new
Browse files
app.py
CHANGED
|
@@ -1,22 +1,31 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
if not os.getenv("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"):
|
| 4 |
-
raise ValueError("OPENAI_API_KEY must be set")
|
| 5 |
-
|
| 6 |
from langchain.agents import initialize_agent
|
| 7 |
from langchain.llms import OpenAI
|
| 8 |
from gradio_tools import (StableDiffusionTool, ImageCaptioningTool, StableDiffusionPromptGeneratorTool,
|
| 9 |
TextToVideoTool)
|
| 10 |
-
|
| 11 |
from langchain.memory import ConversationBufferMemory
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
memory = ConversationBufferMemory(memory_key="chat_history")
|
| 15 |
-
tools = [StableDiffusionTool().langchain, ImageCaptioningTool().langchain,
|
| 16 |
-
StableDiffusionPromptGeneratorTool().langchain, TextToVideoTool().langchain]
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
output = agent.run(
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from langchain.agents import initialize_agent
|
| 3 |
from langchain.llms import OpenAI
|
| 4 |
from gradio_tools import (StableDiffusionTool, ImageCaptioningTool, StableDiffusionPromptGeneratorTool,
|
| 5 |
TextToVideoTool)
|
|
|
|
| 6 |
from langchain.memory import ConversationBufferMemory
|
| 7 |
|
| 8 |
+
# Set the API key
|
| 9 |
+
os.environ["OPENAI_API_KEY"] = "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"
|
| 10 |
+
|
| 11 |
+
llm = OpenAI(api_key=os.getenv("OPENAI_API_KEY"), temperature=0)
|
| 12 |
memory = ConversationBufferMemory(memory_key="chat_history")
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Initialize tools
|
| 15 |
+
tools = [
|
| 16 |
+
StableDiffusionTool().langchain,
|
| 17 |
+
ImageCaptioningTool().langchain,
|
| 18 |
+
StableDiffusionPromptGeneratorTool().langchain,
|
| 19 |
+
TextToVideoTool().langchain,
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
# Initialize the agent
|
| 23 |
+
agent = initialize_agent(tools, llm, memory=memory, agent="zero-shot-react-description", verbose=True)
|
| 24 |
|
| 25 |
+
# Run the agent
|
| 26 |
+
output = agent.run(
|
| 27 |
+
input=("Please create a photo of a dog riding a skateboard "
|
| 28 |
+
"but improve my prompt prior to using an image generator. "
|
| 29 |
+
"Please caption the generated image and create a video for it using the improved prompt.")
|
| 30 |
+
)
|
| 31 |
+
print(output)
|