|
import streamlit as st |
|
import openai |
|
|
|
|
|
openai.api_key = "TU_API_KEY_AQUÍ" |
|
|
|
|
|
st.title("Chat IA sin restricciones 🤖") |
|
|
|
|
|
user_input = st.text_input("Hazme una pregunta:") |
|
|
|
|
|
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}") |
|
|