Continue improving conversational agent
Browse files- app.py +17 -17
- 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 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 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.
|
|
|
|
| 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
|
| 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
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
gr.HTML("<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>")
|
| 126 |
|
| 127 |
state = gr.State()
|
| 128 |
-
|
| 129 |
|
| 130 |
-
message.submit(chat, inputs=[message, state,
|
| 131 |
-
submit.click(chat, inputs=[message, state,
|
| 132 |
|
| 133 |
openai_api_key_textbox.change(set_openai_api_key,
|
| 134 |
-
inputs=[openai_api_key_textbox,
|
| 135 |
-
outputs=[
|
| 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:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:faa87e7f6fe17256601a99f3b7c40ad18dc06c8e9eb366a97c1c8080b1e1a1ef
|
| 3 |
+
size 166113
|