Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from gtts import gTTS
|
4 |
-
import streamlit.components.v1 as stc
|
5 |
|
6 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
7 |
system_prompt = "Tu nombre es Xaman 3.0"
|
@@ -45,12 +44,12 @@ def generate(
|
|
45 |
do_sample=True,
|
46 |
seed=42,
|
47 |
)
|
48 |
-
|
49 |
formatted_prompt = format_prompt(user_input, history)
|
50 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
51 |
response = " ".join(response.token.text for response in stream)
|
52 |
|
53 |
-
st.
|
54 |
audio_file = text_to_speech(response, speed=1.2)
|
55 |
st.audio(audio_file, format="audio/mp3", start_time=0, key='audio')
|
56 |
|
@@ -59,6 +58,17 @@ def generate(
|
|
59 |
if "history" not in st.session_state:
|
60 |
st.session_state.history = []
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
output = generate(user_input, history=st.session_state.history)
|
64 |
-
st.session_state.history.append((user_input, output))
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from gtts import gTTS
|
|
|
4 |
|
5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
system_prompt = "Tu nombre es Xaman 3.0"
|
|
|
44 |
do_sample=True,
|
45 |
seed=42,
|
46 |
)
|
47 |
+
|
48 |
formatted_prompt = format_prompt(user_input, history)
|
49 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
50 |
response = " ".join(response.token.text for response in stream)
|
51 |
|
52 |
+
st.textbox(response)
|
53 |
audio_file = text_to_speech(response, speed=1.2)
|
54 |
st.audio(audio_file, format="audio/mp3", start_time=0, key='audio')
|
55 |
|
|
|
58 |
if "history" not in st.session_state:
|
59 |
st.session_state.history = []
|
60 |
|
61 |
+
st.title("Chatbot Interactivo")
|
62 |
+
user_input = st.text_area(label="Usuario", value="Escribe aqu铆 tu mensaje", height=200)
|
63 |
+
|
64 |
+
st.subheader("Historial de Conversaci贸n")
|
65 |
+
for user_prompt, bot_response in st.session_state.history:
|
66 |
+
st.write(f"Usuario: {user_prompt}")
|
67 |
+
st.write(f"Bot: {bot_response}")
|
68 |
+
st.markdown("---")
|
69 |
+
|
70 |
output = generate(user_input, history=st.session_state.history)
|
71 |
+
st.session_state.history.append((user_input, output))
|
72 |
+
|
73 |
+
audio_file = text_to_speech(output, speed=1.2)
|
74 |
+
st.audio(audio_file, format="audio/mp3", start_time=0, key='audio')
|