plAIn_st / app.py
rdlf's picture
Update app.py
0efec60 verified
raw
history blame
1.65 kB
import streamlit as st
from PIL import Image
from groq import Groq
import os
# Initialize the Groq client
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
# Function to clear the input field
def clear_input():
st.session_state["user_input"] = ""
# Function to process the input text
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. Muestra siempre primero el texto corregido y a continuaci贸n las explicaciones, con el siguiente lenguaje de marcado:
###TEXTO CORREGIDO###
###EXPLICACI脫N###
"
'''
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
# Main app
st.write("# Inicio")
# Create a text input widget with session state
user_input = st.text_input('Pega tu texto:', '', key="user_input")
# Create a button to submit the input
if st.button("Enviar"):
processed_output = process_text(user_input)
st.write('Texto procesado:', processed_output)
clear_input() # Clear the input field after processing