Spaces:
Sleeping
Sleeping
fahad11182
commited on
Commit
•
f74aef8
1
Parent(s):
2ad2d11
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,10 @@ from huggingface_hub import InferenceClient
|
|
3 |
from gtts import gTTS
|
4 |
import base64
|
5 |
import os
|
|
|
|
|
|
|
|
|
6 |
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
@@ -22,7 +26,7 @@ def generate_response(message, system_message, max_tokens, temperature, top_p):
|
|
22 |
response += token
|
23 |
|
24 |
# Generate speech from the response text using gTTS
|
25 |
-
tts = gTTS(text=response, lang='en')
|
26 |
audio_file = "response.mp3"
|
27 |
tts.save(audio_file)
|
28 |
return response, audio_file
|
@@ -32,7 +36,7 @@ def get_base64_audio(audio_file):
|
|
32 |
audio_data = f.read()
|
33 |
return base64.b64encode(audio_data).decode()
|
34 |
|
35 |
-
st.title("Chatbot with Voice Response")
|
36 |
|
37 |
message = st.text_input("Enter your message:")
|
38 |
system_message = st.text_input("System message:", value="You are a friendly Chatbot.")
|
|
|
3 |
from gtts import gTTS
|
4 |
import base64
|
5 |
import os
|
6 |
+
from langdetect import detect, DetectorFactory
|
7 |
+
|
8 |
+
# To ensure consistent results from langdetect
|
9 |
+
DetectorFactory.seed = 0
|
10 |
|
11 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
12 |
|
|
|
26 |
response += token
|
27 |
|
28 |
# Generate speech from the response text using gTTS
|
29 |
+
tts = gTTS(text=response, lang='en' if detect(message) == 'en' else 'ar')
|
30 |
audio_file = "response.mp3"
|
31 |
tts.save(audio_file)
|
32 |
return response, audio_file
|
|
|
36 |
audio_data = f.read()
|
37 |
return base64.b64encode(audio_data).decode()
|
38 |
|
39 |
+
st.title("A Chatbot with Voice Response")
|
40 |
|
41 |
message = st.text_input("Enter your message:")
|
42 |
system_message = st.text_input("System message:", value="You are a friendly Chatbot.")
|