Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,11 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from langchain.agents import initialize_agent
|
3 |
-
from langchain.llms import OpenAI
|
4 |
-
from gradio_tools.tools import (StableDiffusionTool, ImageCaptioningTool, StableDiffusionPromptGeneratorTool,
|
5 |
-
TextToVideoTool)
|
6 |
-
|
7 |
-
from langchain.memory import ConversationBufferMemory
|
8 |
-
|
9 |
-
llm = OpenAI(openai_api_key="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",temperature=0)
|
10 |
-
memory = ConversationBufferMemory(memory_key="chat_history")
|
11 |
-
tools = [StableDiffusionTool().langchain, ImageCaptioningTool().langchain,
|
12 |
-
StableDiffusionPromptGeneratorTool().langchain, TextToVideoTool().langchain]
|
13 |
-
|
14 |
-
agent = initialize_agent(tools, llm, memory=memory, agent="conversational-react-description", verbose=True)
|
15 |
|
16 |
def run_text(text, state):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
21 |
|
22 |
with gr.Blocks(css="#chatbot {overflow:auto; height:500px;}") as demo:
|
23 |
chatbot = gr.Chatbot(elem_id="chatbot",show_label=False)
|
@@ -30,7 +18,8 @@ with gr.Blocks(css="#chatbot {overflow:auto; height:500px;}") as demo:
|
|
30 |
with gr.Column(scale=0.20, min_width=0):
|
31 |
clear = gr.Button("🔄Clear️")
|
32 |
|
33 |
-
txt.submit(run_text, [txt, state], [chatbot])
|
34 |
-
|
|
|
35 |
|
36 |
-
demo.queue(concurrency_count=10).launch(server_name="0.0.0.0", server_port=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
def run_text(text, state):
|
3 |
+
res = "hello"
|
4 |
+
state = state + [(text, res)]
|
5 |
+
return state,state
|
6 |
+
|
7 |
+
with gr.Row():
|
8 |
+
lang = gr.Radio(choices=['OpenAI', 'Bard'], value='OpenAI', label='llm')
|
9 |
|
10 |
with gr.Blocks(css="#chatbot {overflow:auto; height:500px;}") as demo:
|
11 |
chatbot = gr.Chatbot(elem_id="chatbot",show_label=False)
|
|
|
18 |
with gr.Column(scale=0.20, min_width=0):
|
19 |
clear = gr.Button("🔄Clear️")
|
20 |
|
21 |
+
txt.submit(run_text, [txt, state], [chatbot,state])
|
22 |
+
txt.submit(lambda: "", None, txt)
|
23 |
+
run.click(run_text, [txt, state], [chatbot,state])
|
24 |
|
25 |
+
demo.queue(concurrency_count=10).launch(server_name="0.0.0.0", server_port=7861)
|