archerlinn commited on
Commit
2922314
·
1 Parent(s): 3c74ceb
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -1,30 +1,21 @@
1
- from gradio_tool import GradioTool
2
  import os
 
 
 
 
 
3
 
4
- class StableDiffusionTool(GradioTool):
5
- """Tool for calling stable diffusion from llm"""
6
 
7
- def __init__(
8
- self,
9
- name="StableDiffusion",
10
- description=(
11
- "An image generator. Use this to generate images based on "
12
- "text input. Input should be a description of what the image should "
13
- "look like. The output will be a path to an image file."
14
- ),
15
- src="gradio-client-demos/stable-diffusion",
16
- hf_token=None,
17
- ) -> None:
18
- super().__init__(name, description, src, hf_token)
19
 
20
- def create_job(self, query: str) -> Job:
21
- return self.client.submit(query, "", 9, fn_index=1)
22
 
23
- def postprocess(self, output: str) -> str:
24
- return [os.path.join(output, i) for i in os.listdir(output) if not i.endswith("json")][0]
25
-
26
- def _block_input(self, gr) -> "gr.components.Component":
27
- return gr.Textbox()
28
-
29
- def _block_output(self, gr) -> "gr.components.Component":
30
- return gr.Image()
 
 
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
+ tools = [StableDiffusionTool().langchain, ImageCaptioningTool().langchain,
14
+ StableDiffusionPromptGeneratorTool().langchain, TextToVideoTool().langchain]
 
 
 
 
 
 
 
 
15
 
 
 
16
 
17
+ agent = initialize_agent(tools, llm, memory=memory, agent="conversational-react-description", verbose=True)
18
+ output = agent.run(input=("Please create a photo of a dog riding a skateboard "
19
+ "but improve my prompt prior to using an image generator."
20
+ "Please caption the generated image and create a video for it using the improved prompt."))
21
+ print(output)