Add duplicate space icon and change app header
Browse files
app.py
CHANGED
|
@@ -9,8 +9,8 @@ import gradio as gr
|
|
| 9 |
import requests
|
| 10 |
|
| 11 |
# UNCOMMENT TO USE WHISPER
|
| 12 |
-
import warnings
|
| 13 |
-
import whisper
|
| 14 |
|
| 15 |
from langchain import ConversationChain, LLMChain
|
| 16 |
|
|
@@ -19,7 +19,6 @@ from langchain.chains.conversation.memory import ConversationBufferMemory
|
|
| 19 |
from langchain.llms import OpenAI
|
| 20 |
from threading import Lock
|
| 21 |
|
| 22 |
-
|
| 23 |
# Console to variable
|
| 24 |
from io import StringIO
|
| 25 |
import sys
|
|
@@ -59,9 +58,9 @@ POLLY_VOICE_DATA = PollyVoiceData()
|
|
| 59 |
|
| 60 |
|
| 61 |
# UNCOMMENT TO USE WHISPER
|
| 62 |
-
warnings.filterwarnings("ignore")
|
| 63 |
-
WHISPER_MODEL = whisper.load_model("tiny")
|
| 64 |
-
print("WHISPER_MODEL", WHISPER_MODEL)
|
| 65 |
|
| 66 |
|
| 67 |
# UNCOMMENT TO USE WHISPER
|
|
@@ -284,11 +283,11 @@ class ChatWrapper:
|
|
| 284 |
self.lock = Lock()
|
| 285 |
|
| 286 |
def __call__(
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
):
|
| 293 |
"""Execute the chat functionality."""
|
| 294 |
self.lock.acquire()
|
|
@@ -308,7 +307,8 @@ class ChatWrapper:
|
|
| 308 |
openai.api_key = api_key
|
| 309 |
output, hidden_text = run_chain(chain, inp, capture_hidden_text=trace_chain)
|
| 310 |
|
| 311 |
-
output = transform_text(output, express_chain, num_words, formality, anticipation_level, joy_level,
|
|
|
|
| 312 |
fear_level, surprise_level, sadness_level, disgust_level, anger_level,
|
| 313 |
translate_to, literary_style)
|
| 314 |
|
|
@@ -439,7 +439,8 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 439 |
with gr.Tab("Chat"):
|
| 440 |
with gr.Row():
|
| 441 |
with gr.Column():
|
| 442 |
-
gr.Markdown(
|
|
|
|
| 443 |
|
| 444 |
openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
|
| 445 |
show_label=False, lines=1, type='password')
|
|
@@ -513,7 +514,8 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 513 |
TRANSLATE_TO_DEFAULT, "Arabic", "Arabic (Gulf)", "Catalan", "Chinese (Cantonese)", "Chinese (Mandarin)",
|
| 514 |
"Danish", "Dutch", "English (Australian)", "English (British)", "English (Indian)", "English (New Zealand)",
|
| 515 |
"English (South African)", "English (US)", "English (Welsh)", "Finnish", "French", "French (Canadian)",
|
| 516 |
-
"German", "German (Austrian)", "Georgian", "Hindi", "Icelandic", "Indonesian", "Italian", "Japanese",
|
|
|
|
| 517 |
"Portuguese (Brazilian)", "Portuguese (European)", "Romanian", "Russian", "Spanish (European)",
|
| 518 |
"Spanish (Mexican)", "Spanish (US)", "Swedish", "Turkish", "Ukrainian", "Welsh",
|
| 519 |
"emojis", "Gen Z slang", "how the stereotypical Karen would say it", "Klingon",
|
|
@@ -599,13 +601,20 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 599 |
outputs=[num_words_state])
|
| 600 |
|
| 601 |
gr.HTML("""
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
express_chain_state, num_words_state, formality_state,
|
| 610 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
| 611 |
surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
|
|
@@ -613,7 +622,8 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 613 |
# outputs=[chatbot, history_state, video_html, my_file, message])
|
| 614 |
outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
|
| 615 |
|
| 616 |
-
submit.click(chat, inputs=[openai_api_key_textbox, message, history_state, chain_state, trace_chain_state,
|
|
|
|
| 617 |
express_chain_state, num_words_state, formality_state,
|
| 618 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
| 619 |
surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
|
|
|
|
| 9 |
import requests
|
| 10 |
|
| 11 |
# UNCOMMENT TO USE WHISPER
|
| 12 |
+
# import warnings
|
| 13 |
+
# import whisper
|
| 14 |
|
| 15 |
from langchain import ConversationChain, LLMChain
|
| 16 |
|
|
|
|
| 19 |
from langchain.llms import OpenAI
|
| 20 |
from threading import Lock
|
| 21 |
|
|
|
|
| 22 |
# Console to variable
|
| 23 |
from io import StringIO
|
| 24 |
import sys
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
# UNCOMMENT TO USE WHISPER
|
| 61 |
+
# warnings.filterwarnings("ignore")
|
| 62 |
+
# WHISPER_MODEL = whisper.load_model("tiny")
|
| 63 |
+
# print("WHISPER_MODEL", WHISPER_MODEL)
|
| 64 |
|
| 65 |
|
| 66 |
# UNCOMMENT TO USE WHISPER
|
|
|
|
| 283 |
self.lock = Lock()
|
| 284 |
|
| 285 |
def __call__(
|
| 286 |
+
self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain],
|
| 287 |
+
trace_chain: bool, speak_text: bool, express_chain: Optional[LLMChain],
|
| 288 |
+
num_words, formality, anticipation_level, joy_level, trust_level,
|
| 289 |
+
fear_level, surprise_level, sadness_level, disgust_level, anger_level,
|
| 290 |
+
translate_to, literary_style
|
| 291 |
):
|
| 292 |
"""Execute the chat functionality."""
|
| 293 |
self.lock.acquire()
|
|
|
|
| 307 |
openai.api_key = api_key
|
| 308 |
output, hidden_text = run_chain(chain, inp, capture_hidden_text=trace_chain)
|
| 309 |
|
| 310 |
+
output = transform_text(output, express_chain, num_words, formality, anticipation_level, joy_level,
|
| 311 |
+
trust_level,
|
| 312 |
fear_level, surprise_level, sadness_level, disgust_level, anger_level,
|
| 313 |
translate_to, literary_style)
|
| 314 |
|
|
|
|
| 439 |
with gr.Tab("Chat"):
|
| 440 |
with gr.Row():
|
| 441 |
with gr.Column():
|
| 442 |
+
gr.Markdown(
|
| 443 |
+
"<h4><center>Conversational Agent leveraging</br><center><i>GPT + WolframAlpha + Whisper + LangChain</center></i></h4>")
|
| 444 |
|
| 445 |
openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
|
| 446 |
show_label=False, lines=1, type='password')
|
|
|
|
| 514 |
TRANSLATE_TO_DEFAULT, "Arabic", "Arabic (Gulf)", "Catalan", "Chinese (Cantonese)", "Chinese (Mandarin)",
|
| 515 |
"Danish", "Dutch", "English (Australian)", "English (British)", "English (Indian)", "English (New Zealand)",
|
| 516 |
"English (South African)", "English (US)", "English (Welsh)", "Finnish", "French", "French (Canadian)",
|
| 517 |
+
"German", "German (Austrian)", "Georgian", "Hindi", "Icelandic", "Indonesian", "Italian", "Japanese",
|
| 518 |
+
"Korean", "Norwegian", "Polish",
|
| 519 |
"Portuguese (Brazilian)", "Portuguese (European)", "Romanian", "Russian", "Spanish (European)",
|
| 520 |
"Spanish (Mexican)", "Spanish (US)", "Swedish", "Turkish", "Ukrainian", "Welsh",
|
| 521 |
"emojis", "Gen Z slang", "how the stereotypical Karen would say it", "Klingon",
|
|
|
|
| 601 |
outputs=[num_words_state])
|
| 602 |
|
| 603 |
gr.HTML("""
|
| 604 |
+
<p>This application, developed by <a href='https://www.linkedin.com/in/javafxpert/'>James L. Weaver</a>,
|
| 605 |
+
demonstrates a conversational agent implemented with OpenAI GPT-3.5 and LangChain.
|
| 606 |
+
When necessary, it leverages tools for complex math, searching the internet, and accessing news and weather.
|
| 607 |
+
For faster inference without waiting in queue, you may duplicate the space.
|
| 608 |
+
</p>""")
|
| 609 |
+
|
| 610 |
+
gr.HTML("""<center>
|
| 611 |
+
<a href="https://huggingface.co/spaces/JavaFXpert/Chat-GPT-LangChain?duplicate=true">
|
| 612 |
+
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
| 613 |
+
Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a>
|
| 614 |
+
</center>""")
|
| 615 |
+
|
| 616 |
+
message.submit(chat, inputs=[openai_api_key_textbox, message, history_state, chain_state, trace_chain_state,
|
| 617 |
+
speak_text_state,
|
| 618 |
express_chain_state, num_words_state, formality_state,
|
| 619 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
| 620 |
surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
|
|
|
|
| 622 |
# outputs=[chatbot, history_state, video_html, my_file, message])
|
| 623 |
outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
|
| 624 |
|
| 625 |
+
submit.click(chat, inputs=[openai_api_key_textbox, message, history_state, chain_state, trace_chain_state,
|
| 626 |
+
speak_text_state,
|
| 627 |
express_chain_state, num_words_state, formality_state,
|
| 628 |
anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
|
| 629 |
surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
|