Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,11 @@ import streamlit as st
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from gtts import gTTS
|
4 |
import base64
|
|
|
|
|
5 |
|
6 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
7 |
-
system_prompt = "Tu nombre ser谩 Chaman 3.0 una IA conductual, tu rol es la bio茅tica y el existencialismo est贸ico, hol铆sticamente."
|
8 |
system_prompt_sent = False
|
9 |
|
10 |
def format_prompt(message, history):
|
@@ -27,6 +29,12 @@ def text_to_speech(text, speed=2.0):
|
|
27 |
tts = gTTS(text=text, lang='es')
|
28 |
audio_file_path = 'output.mp3'
|
29 |
tts.save(audio_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return audio_file_path
|
31 |
|
32 |
def generate(user_input, history, temperature=None, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0):
|
@@ -54,7 +62,7 @@ def generate(user_input, history, temperature=None, max_new_tokens=2048, top_p=0
|
|
54 |
|
55 |
response = ' '.join(response.split()).replace('</s>', '')
|
56 |
|
57 |
-
audio_file_path = text_to_speech(response)
|
58 |
audio_file = open(audio_file_path, 'rb')
|
59 |
audio_bytes = audio_file.read()
|
60 |
|
@@ -73,7 +81,7 @@ st.text_area("Salida del Chatbot", value=output, height=200, max_chars=500, key=
|
|
73 |
|
74 |
st.markdown(
|
75 |
f"""
|
76 |
-
<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_bytes).decode()}" type="audio/mp3"
|
77 |
""",
|
78 |
unsafe_allow_html=True
|
79 |
-
)
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from gtts import gTTS
|
4 |
import base64
|
5 |
+
from pydub import AudioSegment
|
6 |
+
from pydub.playback import play
|
7 |
|
8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
9 |
+
system_prompt = "Tu nombre ser谩 Chaman 3.0 una IA conductual, hablaras espa帽ol tu rol es la bio茅tica y el existencialismo est贸ico, hol铆sticamente."
|
10 |
system_prompt_sent = False
|
11 |
|
12 |
def format_prompt(message, history):
|
|
|
29 |
tts = gTTS(text=text, lang='es')
|
30 |
audio_file_path = 'output.mp3'
|
31 |
tts.save(audio_file_path)
|
32 |
+
|
33 |
+
# Ajustar la velocidad del audio con pydub
|
34 |
+
sound = AudioSegment.from_mp3(audio_file_path)
|
35 |
+
sound = sound.speedup(playback_speed=speed)
|
36 |
+
sound.export(audio_file_path, format="mp3")
|
37 |
+
|
38 |
return audio_file_path
|
39 |
|
40 |
def generate(user_input, history, temperature=None, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0):
|
|
|
62 |
|
63 |
response = ' '.join(response.split()).replace('</s>', '')
|
64 |
|
65 |
+
audio_file_path = text_to_speech(response, speed=2.0)
|
66 |
audio_file = open(audio_file_path, 'rb')
|
67 |
audio_bytes = audio_file.read()
|
68 |
|
|
|
81 |
|
82 |
st.markdown(
|
83 |
f"""
|
84 |
+
<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_bytes).decode()}" type="audio/mp3" id="audio_player"></audio>
|
85 |
""",
|
86 |
unsafe_allow_html=True
|
87 |
+
)
|