File size: 859 Bytes
71acbaf
bc93fdd
 
 
 
71acbaf
 
bc93fdd
 
 
 
71acbaf
bc93fdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import streamlit as st
import openai

# Configura tu clave de OpenAI
openai.api_key = "TU_API_KEY_AQUÍ"

# Título de la aplicación
st.title("Chat IA sin restricciones 🤖")

# Input del usuario
user_input = st.text_input("Hazme una pregunta:")

# Procesa la respuesta de la IA
if user_input:
    try:
        with st.spinner("Pensando... 🤔"):
            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo",
                messages=[
                    {"role": "system", "content": "Eres un asistente útil y sin sesgos."},
                    {"role": "user", "content": user_input},
                ],
            )
            answer = response["choices"][0]["message"]["content"]
        st.success("¡Respuesta lista! 😊")
        st.write(answer)
    except Exception as e:
        st.error(f"Hubo un error: {e}")