Spaces:
Sleeping
Sleeping
File size: 3,724 Bytes
f221d3b 674f02f f221d3b 3ac27b6 f221d3b 6b6c0d0 f221d3b 3ac27b6 f221d3b a721a61 3ac27b6 a721a61 f221d3b 84aea87 a721a61 8a46768 a721a61 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
import os
import sys
# βββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1) Forzar a Streamlit a usar /tmp/.streamlit (es escribible en HF Spaces)
# βββββββββββββββββββββββββββββββββββββββββββββββββββ
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
# Nos aseguramos de que /tmp/.streamlit exista
try:
os.makedirs("/tmp/.streamlit", exist_ok=True)
except Exception:
pass
# βββββββββββββββββββββββββββββββββββββββββββββββββββ
# 2) Meter src/ en sys.path para hallar agent/ y tools/
# βββββββββββββββββββββββββββββββββββββββββββββββββββ
HERE = os.path.dirname(__file__) # apunta a /app/src
if HERE not in sys.path:
sys.path.insert(0, HERE)
# βββββββββββββββββββββββββββββββββββββββββββββββββββ
# 3) Ahora sΓ importamos Streamlit y el resto
# βββββββββββββββββββββββββββββββββββββββββββββββββββ
import streamlit as st
from agent.linkedin_agent import create_agent
from tools.web_search_tool import get_web_search_tool
from agents import Runner
# β¦ resto de tu cΓ³digo de UI/ lΓ³gica de Streamlit β¦
st.set_page_config(page_title="Buscador de Perfiles LinkedIn", layout="centered")
# Verificamos que la clave estΓ© presente en entorno
if not os.getenv("OPENAI_API_KEY"):
st.error("β Por favor define la variable de entorno OPENAI_API_KEY.")
st.stop()
# Instanciamos una sola vez el agente al arrancar la app
agent = create_agent()
st.title("π Agente: BΓΊsqueda de Perfiles LinkedIn")
st.write("Ingresa la descripciΓ³n de la oferta y la cantidad de perfiles que deseas encontrar.")
# Contenedor para historial de chat
if "history" not in st.session_state:
st.session_state.history = []
# Formulario para que el usuario ingrese oferta + nΓΊmero de perfiles
with st.form(key="oferta_form", clear_on_submit=False):
oferta = st.text_area("π° DescripciΓ³n de la oferta de empleo:", height=150)
num_perfiles = st.number_input(
"π’ Cantidad de perfiles a buscar:",
min_value=1, max_value=20, value=5
)
enviar = st.form_submit_button(label="Enviar al agente")
# Cuando el usuario hace clic en βEnviarβ
if enviar and oferta:
# Agregamos el mensaje del usuario al historial
st.session_state.history.append(("usuario", oferta))
# Construimos el prompt tal como espera el agente: oferta + N
prompt = f"Oferta: {oferta}\nNΓΊmero perfiles: {num_perfiles}"
# Ejecutamos el agente de forma sΓncrona
# Runner.run_sync se encarga de bloquear hasta obtener la salida final
resultado = Runner.run_sync(agent, prompt)
respuesta = resultado.final_output
# Agregamos la respuesta del agente al historial
st.session_state.history.append(("agente", respuesta))
# Mostramos el βchatβ en orden cronolΓ³gico
st.markdown("""---""")
st.markdown("### π¬ Historial de Chat")
for quien, texto in st.session_state.history:
if quien == "usuario":
st.markdown(f"**TΓΊ:** {texto}")
else:
st.markdown(f"**Agente:** {texto}")
# Al pie, sugerimos al usuario limpiar el historial si desea volver a empezar
if st.button("π Limpiar historial"):
st.session_state.history = []
|