Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| from PIL import Image | |
| import os | |
| from gtts import gTTS | |
| from groq import Groq | |
| st.image('calamo.png', caption="", use_column_width=False) | |
| client = Groq( | |
| api_key=os.environ.get("GROQ_API_KEY"), | |
| ) | |
| # Other content of your app | |
| st.title("plAIn Voice") | |
| # Define a function to process the input | |
| def process_text(input_text): | |
| prompt = ''' | |
| Eres un experto en lenguaje claro. Las pautas b谩sicas para lenguaje claro son: | |
| - Expresar una idea por oraci贸n. | |
| - Utilizar oraciones de treinta palabras o menos. | |
| - Evitar la jerga. | |
| - Seguir el orden sujeto, verbo y predicado. | |
| - Utilizar una estructura l贸gica, organizando la informaci贸n de manera clara y coherente. | |
| Eval煤a la calidad del lenguaje de este texto y sugiere las correcciones oportunas:" | |
| ''' | |
| input = prompt + input_text | |
| chat_completion = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": input, | |
| } | |
| ], | |
| model="mixtral-8x7b-32768", | |
| ) | |
| return (chat_completion.choices[0].message.content) | |
| def generate_audio(input_text): | |
| tts = process_text(input_text) | |
| speech = gTTS(text=tts, lang='es-ES', slow=False) | |
| speech.save("gtts_out.mp3") | |
| return "gtts_out.mp3" | |
| user_input = st.text_input("Pega un texto para aclararlo y escuchar una lectura.") | |
| if st.button('Aclarar'): | |
| if user_input == "": | |
| st.write("Pega un texto aqu铆") | |
| else: | |
| speech_file = generate_audio(user_input) | |
| st.audio(speech_file, format='audio/mp3') | |