JLW commited on
Commit
7a3976e
·
1 Parent(s): 9fb96db

Continue improving conversational agent

Browse files
Files changed (2) hide show
  1. app.py +17 -17
  2. videos/tempfile.mp4 +2 -2
app.py CHANGED
@@ -46,14 +46,13 @@ def chat(
46
  print("inp: " + inp)
47
  history = history or []
48
  # If chain is None, that is because no API key was provided.
49
- if chain is None:
50
- history.append((inp, "Please paste your OpenAI key to use"))
51
- return history, history, None, None
52
- # Run chain and append input.
53
- output = chain.run(input=inp)
54
  history.append((inp, output))
55
  html_video, temp_file = do_html_video_speak(output)
56
- return history, history, html_video, temp_file
57
 
58
 
59
  def do_html_video_speak(words_to_speak):
@@ -83,7 +82,8 @@ block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
83
 
84
  with block:
85
  with gr.Row():
86
- gr.Markdown("<h3><center>Q&A GPT3.5/LangChain</center></h3>")
 
87
 
88
  openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
89
  show_label=False, lines=1, type='password')
@@ -107,7 +107,7 @@ with block:
107
 
108
  gr.Examples(
109
  examples=["How many people live in Canada?",
110
- "What is 13**.3?",
111
  "How much did it rain in SF today?",
112
  "Get me information about the movie 'Avatar'",
113
  "What are the top tech headlines in the US?",
@@ -117,22 +117,22 @@ with block:
117
  )
118
 
119
  gr.HTML("""
120
- This simple application demonstrates some capabilities of GPT-3 in conjunction with the open source
121
- LangChain library. It consists of an agent (backed by a GPT-3 language model) using tools to
122
- answer/execute questions. It is based upon
123
- <a href="https://colab.research.google.com/drive/1ZiU0zU17FeLWKkRbxB6AB_NfqvenJkGF"> this Jupyter notebook</a>.""")
124
 
125
  gr.HTML("<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>")
126
 
127
  state = gr.State()
128
- agent_state = gr.State()
129
 
130
- message.submit(chat, inputs=[message, state, agent_state], outputs=[chatbot, state, video_html, my_file])
131
- submit.click(chat, inputs=[message, state, agent_state], outputs=[chatbot, state, video_html, my_file])
132
 
133
  openai_api_key_textbox.change(set_openai_api_key,
134
- inputs=[openai_api_key_textbox, agent_state],
135
- outputs=[agent_state])
136
 
137
  block.launch(debug = True)
138
 
 
46
  print("inp: " + inp)
47
  history = history or []
48
  # If chain is None, that is because no API key was provided.
49
+ output = "Please paste your OpenAI key to use this application."
50
+ if chain and chain != "":
51
+ # Run chain and append input.
52
+ output = chain.run(input=inp)
 
53
  history.append((inp, output))
54
  html_video, temp_file = do_html_video_speak(output)
55
+ return history, history, html_video, temp_file, ""
56
 
57
 
58
  def do_html_video_speak(words_to_speak):
 
82
 
83
  with block:
84
  with gr.Row():
85
+ with gr.Column():
86
+ gr.Markdown("<h4><center>Conversational Agent using GPT-3.5 & LangChain</center></h4>")
87
 
88
  openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
89
  show_label=False, lines=1, type='password')
 
107
 
108
  gr.Examples(
109
  examples=["How many people live in Canada?",
110
+ "What is 2 to the 30th power?",
111
  "How much did it rain in SF today?",
112
  "Get me information about the movie 'Avatar'",
113
  "What are the top tech headlines in the US?",
 
117
  )
118
 
119
  gr.HTML("""
120
+ This simple application demonstrates a conversational agent implemented with OpenAI GPT-3.5 and LangChain.
121
+ When necessary, it leverages tools for complex math, searching the internet, and accessing news and weather.
122
+ On a desktop, the agent will often speak using using an animated avatar from
123
+ <a href='https://exh.ai/'>Ex-Human</a>.""")
124
 
125
  gr.HTML("<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>")
126
 
127
  state = gr.State()
128
+ chain_state = gr.State()
129
 
130
+ message.submit(chat, inputs=[message, state, chain_state], outputs=[chatbot, state, video_html, my_file, message])
131
+ submit.click(chat, inputs=[message, state, chain_state], outputs=[chatbot, state, video_html, my_file, message])
132
 
133
  openai_api_key_textbox.change(set_openai_api_key,
134
+ inputs=[openai_api_key_textbox, chain_state],
135
+ outputs=[chain_state])
136
 
137
  block.launch(debug = True)
138
 
videos/tempfile.mp4 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:00c48e6bd31e9fac3d2ffc83a9cdc322a45d9b1d37b5beba8bca79b401f48e4d
3
- size 154382
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:faa87e7f6fe17256601a99f3b7c40ad18dc06c8e9eb366a97c1c8080b1e1a1ef
3
+ size 166113