Initial commit
Browse files- .gitattributes +2 -0
- app.py +122 -0
- images/Masahiro.png +3 -0
- requirements.txt +6 -0
- videos/Masahiro.mp4 +3 -0
- videos/tempfile.mp4 +3 -0
.gitattributes
CHANGED
|
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import os
|
| 3 |
+
import datetime
|
| 4 |
+
import openai
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import requests
|
| 7 |
+
|
| 8 |
+
from langchain.agents import load_tools, initialize_agent, get_all_tool_names
|
| 9 |
+
from langchain.llms import OpenAI
|
| 10 |
+
|
| 11 |
+
news_api_key = os.environ["NEWS_API_KEY"]
|
| 12 |
+
tmdb_bearer_token = os.environ["TMDB_BEARER_TOKEN"]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def set_openai_api_key(api_key, agent):
|
| 16 |
+
if api_key:
|
| 17 |
+
tool_names = get_all_tool_names()
|
| 18 |
+
|
| 19 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 20 |
+
llm = OpenAI(model_name="text-davinci-003", temperature=0)
|
| 21 |
+
os.environ["OPENAI_API_KEY"] = ""
|
| 22 |
+
|
| 23 |
+
tools = load_tools(tool_names, llm=llm, news_api_key=news_api_key, tmdb_bearer_token=tmdb_bearer_token)
|
| 24 |
+
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
|
| 25 |
+
return agent
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def chat(inp, history, agent):
|
| 29 |
+
print("\n==== date/time: " + str(datetime.datetime.now()) + " ====")
|
| 30 |
+
print("inp: " + inp)
|
| 31 |
+
history = history or []
|
| 32 |
+
output = agent.run(inp)
|
| 33 |
+
history.append((inp, output))
|
| 34 |
+
return history, history
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def do_html_video_speak(testing):
|
| 38 |
+
headers = {"Authorization": f"Bearer {os.environ['EXHUMAN_API_KEY']}"}
|
| 39 |
+
body = {
|
| 40 |
+
'bot_name': 'Masahiro',
|
| 41 |
+
'bot_response': 'This is a test. This is a test. This is a test. This is a test. This is a test',
|
| 42 |
+
'voice_name': 'Masahiro-EN'
|
| 43 |
+
}
|
| 44 |
+
api_endpoint = "https://api.exh.ai/animations/v1/generate_lipsync"
|
| 45 |
+
res = requests.post(api_endpoint, json=body, headers=headers)
|
| 46 |
+
|
| 47 |
+
html_video = '<pre>no video</pre>'
|
| 48 |
+
if isinstance(res.content, bytes):
|
| 49 |
+
response_stream = io.BytesIO(res.content)
|
| 50 |
+
with open('videos/tempfile.mp4', 'wb') as f:
|
| 51 |
+
f.write(response_stream.read())
|
| 52 |
+
temp_file = gr.File("videos/tempfile.mp4")
|
| 53 |
+
temp_file_url = "/file=" + temp_file.value['name']
|
| 54 |
+
html_video = f'<video width="256" height="256" autoplay><source src={temp_file_url} type="video/mp4"></video>'
|
| 55 |
+
else:
|
| 56 |
+
print('video url unknown')
|
| 57 |
+
return html_video, "videos/tempfile.mp4"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
|
| 61 |
+
|
| 62 |
+
with block:
|
| 63 |
+
with gr.Row():
|
| 64 |
+
my_file = gr.File(label="Upload a file", type="file", visible=False)
|
| 65 |
+
|
| 66 |
+
tmp_file = gr.File("videos/Masahiro.mp4", visible=False)
|
| 67 |
+
tmp_file_url = "/file=" + tmp_file.value['name']
|
| 68 |
+
htm_video = f'<video width="256" height="256" autoplay muted loop><source src={tmp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
|
| 69 |
+
video_html = gr.HTML(htm_video)
|
| 70 |
+
|
| 71 |
+
# video_html = gr.HTML("f'<video width=\"512\" height=\"512\" autoplay><source src={tmp_file_url} type=\"video/mp4\"></video>")
|
| 72 |
+
|
| 73 |
+
# video_html = gr.HTML("""<video width="100%" height="100%" controls autoplay loop>
|
| 74 |
+
# <source src="videos/Masahiro.mp4"
|
| 75 |
+
# type="video/mp4"></video>""")
|
| 76 |
+
|
| 77 |
+
gr.Markdown("<h3><center>LangChain AI</center></h3>")
|
| 78 |
+
|
| 79 |
+
openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
|
| 80 |
+
show_label=False, lines=1, type='password')
|
| 81 |
+
|
| 82 |
+
chatbot = gr.Chatbot()
|
| 83 |
+
|
| 84 |
+
with gr.Row():
|
| 85 |
+
message = gr.Textbox(label="What's your question?",
|
| 86 |
+
placeholder="What's the answer to life, the universe, and everything?",
|
| 87 |
+
lines=1)
|
| 88 |
+
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
|
| 89 |
+
test = gr.Button(value="Test", variant="secondary").style(full_width=False)
|
| 90 |
+
|
| 91 |
+
gr.Examples(
|
| 92 |
+
examples=["How many people live in Canada?",
|
| 93 |
+
"What is 13**.3?",
|
| 94 |
+
"How much did it rain in SF today?",
|
| 95 |
+
"Get me information about the movie 'Avatar'",
|
| 96 |
+
"What are the top tech headlines in the US?",
|
| 97 |
+
"On the desk, you see two blue booklets, two purple booklets, and two yellow pairs of sunglasses - "
|
| 98 |
+
"if I remove all the pairs of sunglasses from the desk, how many purple items remain on it?"],
|
| 99 |
+
inputs=message
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
gr.HTML("""
|
| 103 |
+
This simple application demonstrates some capabilities of GPT-3 in conjunction with the open source
|
| 104 |
+
LangChain library. It consists of an agent (backed by a GPT-3 language model) using tools to
|
| 105 |
+
answer/execute questions. It is based upon
|
| 106 |
+
<a href="https://colab.research.google.com/drive/1ZiU0zU17FeLWKkRbxB6AB_NfqvenJkGF"> this Jupyter notebook</a>.""")
|
| 107 |
+
|
| 108 |
+
gr.HTML("<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>")
|
| 109 |
+
|
| 110 |
+
state = gr.State()
|
| 111 |
+
agent_state = gr.State()
|
| 112 |
+
|
| 113 |
+
submit.click(chat, inputs=[message, state, agent_state], outputs=[chatbot, state])
|
| 114 |
+
message.submit(chat, inputs=[message, state, agent_state], outputs=[chatbot, state])
|
| 115 |
+
test.click(do_html_video_speak, inputs=[message], outputs=[video_html, my_file])
|
| 116 |
+
|
| 117 |
+
openai_api_key_textbox.change(set_openai_api_key,
|
| 118 |
+
inputs=[openai_api_key_textbox, agent_state],
|
| 119 |
+
outputs=[agent_state])
|
| 120 |
+
|
| 121 |
+
block.launch(debug = True)
|
| 122 |
+
|
images/Masahiro.png
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai==0.26.0
|
| 2 |
+
gradio==3.16.1
|
| 3 |
+
google-search-results
|
| 4 |
+
google-api-python-client
|
| 5 |
+
langchain==0.0.58
|
| 6 |
+
requests~=2.28.1
|
videos/Masahiro.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ca886517414fae8bcea5a5130ae1d01ef3ead7aed437203abebf032217fd0be6
|
| 3 |
+
size 2425212
|
videos/tempfile.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d0f885d4dc3c110dac03d45fa8acecaff0c1071c3d01db22c24dc683aaf4a9a5
|
| 3 |
+
size 210630
|