thoristhor commited on
Commit
0235a56
1 Parent(s): e26b4b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -28,21 +28,22 @@ memory = ConversationBufferMemory(memory_key="chat_history")
28
  llm=OpenAI(temperature=0)
29
  agent_chain = initialize_agent(tools, llm, agent="conversational-react-description", memory=memory)
30
 
31
- def run_something(isfa: str):
32
- return agent_chain.run(input=isfa)
 
 
 
 
 
33
 
34
  with gr.Blocks() as demo:
35
  chatbot = gr.Chatbot()
 
36
 
37
  with gr.Row():
38
- message = gr.Textbox(
39
- label="What's your question?",
40
- placeholder="Ask questions about the story in the book purple cow",
41
- lines=1,
42
- )
43
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
44
- state = gr.State()
45
- submit.click(run_something, inputs=[message], outputs=[chatbot, state])
46
- message.submit(run_something, inputs=[message], outputs=[chatbot, state])
47
-
48
- demo.launch(debug=True)
 
28
  llm=OpenAI(temperature=0)
29
  agent_chain = initialize_agent(tools, llm, agent="conversational-react-description", memory=memory)
30
 
31
+ def predict(input, history=[]):
32
+ response = agent_chain.run(input)
33
+ history = history + [(input, response)]
34
+ response = history
35
+ # response = [response]
36
+ # return response, response
37
+ return response, response
38
 
39
  with gr.Blocks() as demo:
40
  chatbot = gr.Chatbot()
41
+ state = gr.State([])
42
 
43
  with gr.Row():
44
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
45
+
46
+ txt.submit(predict, [txt, state], [chatbot, state])
47
+ # txt.submit(agent_executor.run, [txt, state], [chatbot, state])
48
+
49
+ demo.launch()