archerlinn commited on
Commit
a4a4372
·
1 Parent(s): 2e93926
Files changed (1) hide show
  1. app.py +20 -21
app.py CHANGED
@@ -1,23 +1,22 @@
1
- import gradio as gr
2
 
3
- def calculator(num1, operation, num2):
4
- if operation == "add":
5
- return num1 + num2
6
- elif operation == "subtract":
7
- return num1 - num2
8
- elif operation == "multiply":
9
- return num1 * num2
10
- elif operation == "divide":
11
- return num1 / num2
12
 
13
- demo = gr.Interface(
14
- calculator,
15
- [
16
- "number",
17
- gr.Radio(["add", "subtract", "multiply", "divide"]),
18
- "number"
19
- ],
20
- "number",
21
- live=True,
22
- )
23
- demo.launch()
 
 
 
 
 
 
 
1
+ import os
2
 
3
+ if not os.getenv("OPENAI_API_KEY"):
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
+ llm = OpenAI(temperature=0)
14
+ memory = ConversationBufferMemory(memory_key="chat_history")
15
+ tools = [StableDiffusionTool().langchain, ImageCaptioningTool().langchain,
16
+ StableDiffusionPromptGeneratorTool().langchain, TextToVideoTool().langchain]
17
+
18
+
19
+ agent = initialize_agent(tools, llm, memory=memory, agent="conversational-react-description", verbose=True)
20
+ output = agent.run(input=("Please create a photo of a dog riding a skateboard "
21
+ "but improve my prompt prior to using an image generator."
22
+ "Please caption the generated image and create a video for it using the improved prompt."))