Spaces:
Build error
Build error
Commit
·
3a31f75
1
Parent(s):
0d510db
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ from threading import Lock
|
|
| 24 |
from io import StringIO
|
| 25 |
import sys
|
| 26 |
import re
|
| 27 |
-
|
| 28 |
from openai.error import AuthenticationError, InvalidRequestError, RateLimitError
|
| 29 |
|
| 30 |
# Pertains to Express-inator functionality
|
|
@@ -50,7 +50,7 @@ TOOLS_LIST = ['serpapi', 'wolfram-alpha', 'pal-math', 'pal-colored-objects', 'ne
|
|
| 50 |
TOOLS_DEFAULT_LIST = ['serpapi', 'wolfram-alpha', 'pal-math', 'pal-colored-objects', 'news-api']
|
| 51 |
BUG_FOUND_MSG = "Congratulations, you've found a bug in this application!"
|
| 52 |
# AUTH_ERR_MSG = "Please paste your OpenAI key from openai.com to use this application. It is not necessary to hit a button or key after pasting it."
|
| 53 |
-
|
| 54 |
MAX_TOKENS = 1024
|
| 55 |
|
| 56 |
LOOPING_TALKING_HEAD = "videos/Masahiro.mp4"
|
|
@@ -266,11 +266,12 @@ def set_openai_api_key(api_key):
|
|
| 266 |
If no api_key, then None is returned.
|
| 267 |
"""
|
| 268 |
if api_key and api_key.startswith("sk-") and len(api_key) > 50:
|
|
|
|
| 269 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 270 |
print("\n\n ++++++++++++++ Setting OpenAI API key ++++++++++++++ \n\n")
|
| 271 |
print(str(datetime.datetime.now()) + ": Before OpenAI, OPENAI_API_KEY length: " + str(
|
| 272 |
len(os.environ["OPENAI_API_KEY"])))
|
| 273 |
-
llm = OpenAI(temperature=0, max_tokens=MAX_TOKENS)
|
| 274 |
print(str(datetime.datetime.now()) + ": After OpenAI, OPENAI_API_KEY length: " + str(
|
| 275 |
len(os.environ["OPENAI_API_KEY"])))
|
| 276 |
chain, express_chain, memory = load_chain(TOOLS_DEFAULT_LIST, llm)
|
|
@@ -281,7 +282,7 @@ def set_openai_api_key(api_key):
|
|
| 281 |
|
| 282 |
print(str(datetime.datetime.now()) + ": After load_chain, OPENAI_API_KEY length: " + str(
|
| 283 |
len(os.environ["OPENAI_API_KEY"])))
|
| 284 |
-
os.environ["OPENAI_API_KEY"] = ""
|
| 285 |
return chain, express_chain, llm, embeddings, qa_chain, memory
|
| 286 |
return None, None, None, None, None, None
|
| 287 |
|
|
@@ -854,7 +855,7 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 854 |
Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a>
|
| 855 |
</center>""")
|
| 856 |
|
| 857 |
-
message.submit(chat, inputs=[
|
| 858 |
speak_text_state, talking_head_state, monologue_state,
|
| 859 |
express_chain_state, num_words_state, formality_state,
|
| 860 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
|
@@ -864,7 +865,7 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 864 |
outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
|
| 865 |
# outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
|
| 866 |
|
| 867 |
-
submit.click(chat, inputs=[
|
| 868 |
speak_text_state, talking_head_state, monologue_state,
|
| 869 |
express_chain_state, num_words_state, formality_state,
|
| 870 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
|
@@ -873,15 +874,6 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 873 |
qa_chain_state, docsearch_state, use_embeddings_state],
|
| 874 |
outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
|
| 875 |
# outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
|
| 876 |
-
|
| 877 |
-
openai_api_key_textbox.change(None,
|
| 878 |
-
inputs=[openai_api_key_textbox],
|
| 879 |
-
outputs=None, _js="(api_key) => localStorage.setItem('open_api_key', api_key)")
|
| 880 |
-
|
| 881 |
-
openai_api_key_textbox.change(set_openai_api_key,
|
| 882 |
-
inputs=[openai_api_key_textbox],
|
| 883 |
-
outputs=[chain_state, express_chain_state, llm_state, embeddings_state,
|
| 884 |
-
qa_chain_state, memory_state])
|
| 885 |
|
| 886 |
block.load(None, inputs=None, outputs=openai_api_key_textbox, _js="()=> localStorage.getItem('open_api_key')")
|
| 887 |
|
|
|
|
| 24 |
from io import StringIO
|
| 25 |
import sys
|
| 26 |
import re
|
| 27 |
+
import OpenAI
|
| 28 |
from openai.error import AuthenticationError, InvalidRequestError, RateLimitError
|
| 29 |
|
| 30 |
# Pertains to Express-inator functionality
|
|
|
|
| 50 |
TOOLS_DEFAULT_LIST = ['serpapi', 'wolfram-alpha', 'pal-math', 'pal-colored-objects', 'news-api']
|
| 51 |
BUG_FOUND_MSG = "Congratulations, you've found a bug in this application!"
|
| 52 |
# AUTH_ERR_MSG = "Please paste your OpenAI key from openai.com to use this application. It is not necessary to hit a button or key after pasting it."
|
| 53 |
+
set_openai_api_key = "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"
|
| 54 |
MAX_TOKENS = 1024
|
| 55 |
|
| 56 |
LOOPING_TALKING_HEAD = "videos/Masahiro.mp4"
|
|
|
|
| 266 |
If no api_key, then None is returned.
|
| 267 |
"""
|
| 268 |
if api_key and api_key.startswith("sk-") and len(api_key) > 50:
|
| 269 |
+
|
| 270 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 271 |
print("\n\n ++++++++++++++ Setting OpenAI API key ++++++++++++++ \n\n")
|
| 272 |
print(str(datetime.datetime.now()) + ": Before OpenAI, OPENAI_API_KEY length: " + str(
|
| 273 |
len(os.environ["OPENAI_API_KEY"])))
|
| 274 |
+
llm = OpenAI(temperature=0.7, max_tokens=MAX_TOKENS)
|
| 275 |
print(str(datetime.datetime.now()) + ": After OpenAI, OPENAI_API_KEY length: " + str(
|
| 276 |
len(os.environ["OPENAI_API_KEY"])))
|
| 277 |
chain, express_chain, memory = load_chain(TOOLS_DEFAULT_LIST, llm)
|
|
|
|
| 282 |
|
| 283 |
print(str(datetime.datetime.now()) + ": After load_chain, OPENAI_API_KEY length: " + str(
|
| 284 |
len(os.environ["OPENAI_API_KEY"])))
|
| 285 |
+
os.environ["OPENAI_API_KEY"] = "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"
|
| 286 |
return chain, express_chain, llm, embeddings, qa_chain, memory
|
| 287 |
return None, None, None, None, None, None
|
| 288 |
|
|
|
|
| 855 |
Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a>
|
| 856 |
</center>""")
|
| 857 |
|
| 858 |
+
message.submit(chat, inputs=[message, history_state, chain_state, trace_chain_state,
|
| 859 |
speak_text_state, talking_head_state, monologue_state,
|
| 860 |
express_chain_state, num_words_state, formality_state,
|
| 861 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
|
|
|
| 865 |
outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
|
| 866 |
# outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
|
| 867 |
|
| 868 |
+
submit.click(chat, inputs=[message, history_state, chain_state, trace_chain_state,
|
| 869 |
speak_text_state, talking_head_state, monologue_state,
|
| 870 |
express_chain_state, num_words_state, formality_state,
|
| 871 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
|
|
|
| 874 |
qa_chain_state, docsearch_state, use_embeddings_state],
|
| 875 |
outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
|
| 876 |
# outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 877 |
|
| 878 |
block.load(None, inputs=None, outputs=openai_api_key_textbox, _js="()=> localStorage.getItem('open_api_key')")
|
| 879 |
|