Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,14 @@ import openai
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 7 |
|
|
|
|
| 8 |
client = OpenAI(api_key=api_key)
|
| 9 |
|
| 10 |
cafchem_tools = [
|
|
@@ -58,8 +63,29 @@ def chat(prompt, tools):
|
|
| 58 |
{"role": "assistant", "content": response.output_text}
|
| 59 |
)
|
| 60 |
last_id = response.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
return "", chat_history
|
| 63 |
|
| 64 |
def clear_history():
|
| 65 |
global chat_history
|
|
@@ -80,18 +106,19 @@ ADME properties of a molecule.
|
|
| 80 |
tools = gr.Radio(choices = ["Yes", "No"],label="Use CafChem tools?",
|
| 81 |
interactive=True)
|
| 82 |
|
| 83 |
-
chatbot = gr.Chatbot(type="messages")
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
msg = gr.Textbox(label="Type your messages here and hit enter.", scale = 2)
|
| 87 |
chat_btn = gr.Button(value = "Send", scale = 0)
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
clear = gr.ClearButton([msg, chatbot])
|
| 91 |
|
| 92 |
|
| 93 |
-
chat_btn.click(chat, [msg, tools], [msg, chatbot])
|
| 94 |
-
msg.submit(chat, [msg, tools], [msg, chatbot])
|
| 95 |
clear.click(clear_history)
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
import gradio as gr
|
| 5 |
+
from elevenlabs.client import ElevenLabs
|
| 6 |
+
from elevenlabs import stream
|
| 7 |
+
import base64
|
| 8 |
|
| 9 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
+
eleven_key = os.getenv("eleven_key")
|
| 11 |
|
| 12 |
+
elevenlabs = ElevenLabs(api_key=eleven_key)
|
| 13 |
client = OpenAI(api_key=api_key)
|
| 14 |
|
| 15 |
cafchem_tools = [
|
|
|
|
| 63 |
{"role": "assistant", "content": response.output_text}
|
| 64 |
)
|
| 65 |
last_id = response.id
|
| 66 |
+
|
| 67 |
+
elita_text = response.output_text
|
| 68 |
+
|
| 69 |
+
voice_settings = {
|
| 70 |
+
"stability": 0.37,
|
| 71 |
+
"similarity_boost": 0.90,
|
| 72 |
+
"style": 0.0,
|
| 73 |
+
"speed": 1.05
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
audio_stream = elevenlabs.text_to_speech.convert(
|
| 77 |
+
text = elita_text,
|
| 78 |
+
voice_id = 'vxO9F6g9yqYJ4RsWvMbc',
|
| 79 |
+
model_id = 'eleven_multilingual_v2',
|
| 80 |
+
output_format='mp3_44100_128',
|
| 81 |
+
voice_settings=voice_settings
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
audio_converted = b"".join(audio_stream)
|
| 85 |
+
audio = base64.b64encode(audio_converted).decode("utf-8")
|
| 86 |
+
audio_player = f'<audio src="data:audio/mpeg;base64,{audio}" controls autoplay></audio>'
|
| 87 |
|
| 88 |
+
return "", chat_history, audio_player
|
| 89 |
|
| 90 |
def clear_history():
|
| 91 |
global chat_history
|
|
|
|
| 106 |
tools = gr.Radio(choices = ["Yes", "No"],label="Use CafChem tools?",
|
| 107 |
interactive=True)
|
| 108 |
|
| 109 |
+
chatbot = gr.Chatbot(type="messages", placeholder="## Looking forward to speaking with you!")
|
| 110 |
|
| 111 |
with gr.Row():
|
| 112 |
msg = gr.Textbox(label="Type your messages here and hit enter.", scale = 2)
|
| 113 |
chat_btn = gr.Button(value = "Send", scale = 0)
|
| 114 |
+
elitas_voice = gr.HTML()
|
| 115 |
|
| 116 |
|
| 117 |
clear = gr.ClearButton([msg, chatbot])
|
| 118 |
|
| 119 |
|
| 120 |
+
chat_btn.click(chat, [msg, tools], [msg, chatbot, elitas_voice])
|
| 121 |
+
msg.submit(chat, [msg, tools], [msg, chatbot, elitas_voice])
|
| 122 |
clear.click(clear_history)
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|