Barto517 commited on
Commit
bc93fdd
verified
1 Parent(s): 71acbaf

openai
streamlit

Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,8 +1,28 @@
1
  import streamlit as st
 
 
 
 
2
 
3
  # T铆tulo de la aplicaci贸n
4
- st.title("Mi Aplicaci贸n Streamlit en Hugging Face 馃殌")
 
 
 
5
 
6
- # Input de usuario
7
- x = st.slider('Selecciona un valor:')
8
- st.write(f'El cuadrado de {x} es {x ** 2}')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import openai
3
+
4
+ # Configura tu clave de OpenAI
5
+ openai.api_key = "TU_API_KEY_AQU脥"
6
 
7
  # T铆tulo de la aplicaci贸n
8
+ st.title("Chat IA sin restricciones 馃")
9
+
10
+ # Input del usuario
11
+ user_input = st.text_input("Hazme una pregunta:")
12
 
13
+ # Procesa la respuesta de la IA
14
+ if user_input:
15
+ try:
16
+ with st.spinner("Pensando... 馃"):
17
+ response = openai.ChatCompletion.create(
18
+ model="gpt-3.5-turbo",
19
+ messages=[
20
+ {"role": "system", "content": "Eres un asistente 煤til y sin sesgos."},
21
+ {"role": "user", "content": user_input},
22
+ ],
23
+ )
24
+ answer = response["choices"][0]["message"]["content"]
25
+ st.success("隆Respuesta lista! 馃槉")
26
+ st.write(answer)
27
+ except Exception as e:
28
+ st.error(f"Hubo un error: {e}")