use gtts
Browse files
app.py
CHANGED
|
@@ -15,8 +15,8 @@ from langchain.chains import RetrievalQA, ConversationalRetrievalChain
|
|
| 15 |
from langchain_groq import ChatGroq
|
| 16 |
from langchain.memory import ConversationBufferMemory
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
def load_groq_api_key():
|
| 21 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 22 |
if not groq_api_key:
|
|
@@ -92,12 +92,23 @@ def init_document_chatbot(knowledgeBase):
|
|
| 92 |
)
|
| 93 |
|
| 94 |
|
| 95 |
-
|
|
|
|
| 96 |
def text_to_speech(text):
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
# 🔹 Generate WordCloud
|
|
|
|
| 15 |
from langchain_groq import ChatGroq
|
| 16 |
from langchain.memory import ConversationBufferMemory
|
| 17 |
|
| 18 |
+
from gtts import gTTS
|
| 19 |
+
|
| 20 |
def load_groq_api_key():
|
| 21 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 22 |
if not groq_api_key:
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
|
| 95 |
+
|
| 96 |
+
|
| 97 |
def text_to_speech(text):
|
| 98 |
+
try:
|
| 99 |
+
# Create audio file with gTTS
|
| 100 |
+
tts = gTTS(text=text, lang='en')
|
| 101 |
+
audio_path = "/tmp/summary_audio.mp3" # Use /tmp/ for Hugging Face Spaces
|
| 102 |
+
tts.save(audio_path)
|
| 103 |
+
|
| 104 |
+
# Verify file was created
|
| 105 |
+
if os.path.exists(audio_path):
|
| 106 |
+
return audio_path
|
| 107 |
+
else:
|
| 108 |
+
raise Exception("Audio file not created")
|
| 109 |
+
except Exception as e:
|
| 110 |
+
print(f"Error in gTTS: {e}")
|
| 111 |
+
return None
|
| 112 |
|
| 113 |
|
| 114 |
# 🔹 Generate WordCloud
|