Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,31 @@
|
|
|
|
|
|
1 |
from langchain.tools import ElevenLabsText2SpeechTool
|
2 |
-
from elevenlabs import set_api_key
|
3 |
-
import gradio as gr
|
4 |
-
import os
|
5 |
-
import requests
|
6 |
|
7 |
-
|
8 |
-
def generate_audio(text):
|
9 |
-
url = "https://api.elevenlabs.io/v1/text-to-speech/mu3rhpR8gxbjSIcSW7fa"
|
10 |
-
payload = {
|
11 |
-
"model_id": "eleven_turbo_v2",
|
12 |
-
"text": text
|
13 |
-
}
|
14 |
-
headers = {
|
15 |
-
"xi-api-key": "866c88e3fe83f2b0de18226738445c8f",
|
16 |
-
"Content-Type": "application/json"
|
17 |
-
}
|
18 |
-
response = requests.request("POST", url, json=payload, headers=headers)
|
19 |
-
return response.json()["audio"]
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.agents import AgentType, initialize_agent, load_tools
|
2 |
+
from langchain.llms import Together
|
3 |
from langchain.tools import ElevenLabsText2SpeechTool
|
4 |
+
from elevenlabs import set_api_key
|
|
|
|
|
|
|
5 |
|
6 |
+
set_api_key("866c88e3fe83f2b0de18226738445c8f")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
# Initialize ElevenLabsText2SpeechTool
|
9 |
+
tts = ElevenLabsText2SpeechTool()
|
10 |
+
|
11 |
+
# Initialize LLM and agent
|
12 |
+
llm = Together(
|
13 |
+
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
14 |
+
temperature=0.7,
|
15 |
+
max_tokens=128,
|
16 |
+
top_k=1,
|
17 |
+
together_api_key="f722a9f6e3afd6b9999e6aee02aeac9e751ea3a67b124c3667ab50c85c7fa99e"
|
18 |
+
)
|
19 |
+
tools = load_tools(["eleven_labs_text2speech"])
|
20 |
+
agent = initialize_agent(
|
21 |
+
tools=tools,
|
22 |
+
llm=llm,
|
23 |
+
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
|
24 |
+
verbose=True
|
25 |
+
)
|
26 |
+
|
27 |
+
# Request a joke and get the path to the audio file
|
28 |
+
response = agent.run("Please provide me with an audio file containing a joke about a tiger")
|
29 |
+
print(response)
|
30 |
+
|
31 |
+
tts.play(response)
|