-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (46 loc) · 2.09 KB
/
Copy pathapp.py
File metadata and controls
54 lines (46 loc) · 2.09 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import streamlit as st
import requests
import json
def get_groq_response(user_input):
api_key = st.secrets["GROQ_API_KEY"] # Obtener la API key desde los secrets de Streamlit
url = "https://api.groq.com/openai/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"messages": [
{"role": "system", "content": "Eres un consejero profesional experto que ayuda a personas desempleadas con recomendaciones laborales."},
{"role": "user", "content": user_input}
],
"model": "llama-3.3-70b-versatile",
"temperature": 0.6,
"max_completion_tokens": 4096,
"top_p": 0.95,
"stream": False
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "Error: No se recibió respuesta.")
# Configurar la interfaz de Streamlit
st.set_page_config(page_title="Chatbot de Orientación Laboral", page_icon="💼")
st.title("Chatbot de Orientación Laboral 🤖")
st.write("Bienvenido/a. Estoy aquí para ayudarte a encontrar oportunidades laborales que se ajusten a tu perfil. Responde algunas preguntas para que pueda ofrecerte recomendaciones personalizadas.")
if "messages" not in st.session_state:
st.session_state["messages"] = []
# Mostrar el historial del chat
for message in st.session_state["messages"]:
with st.chat_message(message["role"]):
st.write(message["content"])
# Input del usuario
user_input = st.chat_input("Escribe tu mensaje aquí...")
if user_input:
# Agregar mensaje del usuario al historial
st.session_state["messages"].append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.write(user_input)
# Obtener respuesta de la API
response = get_groq_response(user_input)
# Agregar respuesta del chatbot al historial
st.session_state["messages"].append({"role": "assistant", "content": response})
with st.chat_message("assistant"):
st.write(response)