Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import streamlit as st
|
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 |
pre_prompt = ""
|
@@ -24,16 +24,12 @@ def format_prompt(message, history):
|
|
24 |
prompt += f"[INST] {message} [/INST]"
|
25 |
return prompt
|
26 |
|
27 |
-
def text_to_speech(text
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
sound.export(audio_file_path, format="mp3")
|
34 |
-
|
35 |
-
return audio_file_path
|
36 |
-
|
37 |
def generate(user_input, history, temperature=None, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
38 |
global pre_prompt_sent
|
39 |
temperature = float(temperature) if temperature is not None else 0.9
|
@@ -70,12 +66,7 @@ if "history" not in st.session_state:
|
|
70 |
|
71 |
user_input = st.text_input(label="", value="")
|
72 |
output, audio_bytes = generate(user_input, history=st.session_state.history)
|
73 |
-
|
74 |
-
if user_input:
|
75 |
-
st.session_state.history.append((user_input, output))
|
76 |
-
|
77 |
st.text_area("Respuesta", value=output, height=400, key="output_text", disabled=True)
|
78 |
-
st.text_input(label="Escribe aquí:", value=user_input, key="user_input", disabled=True)
|
79 |
|
80 |
st.markdown(
|
81 |
f"""
|
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
import base64
|
4 |
from pydub import AudioSegment
|
5 |
from pydub.playback import play
|
6 |
+
import pyttsx3
|
7 |
|
8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
9 |
pre_prompt = ""
|
|
|
24 |
prompt += f"[INST] {message} [/INST]"
|
25 |
return prompt
|
26 |
|
27 |
+
def text_to_speech(text):
|
28 |
+
engine = pyttsx3.init()
|
29 |
+
engine.save_to_file(text, "output_pyttsx3.mp3")
|
30 |
+
engine.runAndWait()
|
31 |
+
return "output_pyttsx3.mp3"
|
32 |
+
|
|
|
|
|
|
|
|
|
33 |
def generate(user_input, history, temperature=None, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
34 |
global pre_prompt_sent
|
35 |
temperature = float(temperature) if temperature is not None else 0.9
|
|
|
66 |
|
67 |
user_input = st.text_input(label="", value="")
|
68 |
output, audio_bytes = generate(user_input, history=st.session_state.history)
|
|
|
|
|
|
|
|
|
69 |
st.text_area("Respuesta", value=output, height=400, key="output_text", disabled=True)
|
|
|
70 |
|
71 |
st.markdown(
|
72 |
f"""
|