Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +18 -33
src/streamlit_app.py
CHANGED
@@ -1,53 +1,49 @@
|
|
1 |
import os
|
2 |
import sys
|
3 |
|
4 |
-
#
|
5 |
-
# 1)
|
6 |
-
#
|
|
|
7 |
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
|
8 |
-
# Nos aseguramos de que /tmp/.streamlit exista
|
9 |
try:
|
10 |
os.makedirs("/tmp/.streamlit", exist_ok=True)
|
11 |
except Exception:
|
|
|
12 |
pass
|
13 |
|
14 |
-
#
|
15 |
-
# 2)
|
16 |
-
#
|
17 |
-
HERE = os.path.dirname(__file__)
|
18 |
if HERE not in sys.path:
|
19 |
sys.path.insert(0, HERE)
|
20 |
|
21 |
-
#
|
22 |
-
# 3)
|
23 |
-
#
|
24 |
import streamlit as st
|
25 |
from agent.linkedin_agent import create_agent
|
26 |
from tools.web_search_tool import get_web_search_tool
|
27 |
from agents import Runner
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
st.set_page_config(page_title="Buscador de Perfiles LinkedIn", layout="centered")
|
34 |
|
35 |
-
# Verificamos que la clave estΓ© presente en entorno
|
36 |
if not os.getenv("OPENAI_API_KEY"):
|
37 |
-
st.error("β Por favor define
|
38 |
st.stop()
|
39 |
|
40 |
-
# Instanciamos una sola vez el agente al arrancar la app
|
41 |
agent = create_agent()
|
42 |
|
43 |
-
st.title("π
|
44 |
st.write("Ingresa la descripciΓ³n de la oferta y la cantidad de perfiles que deseas encontrar.")
|
45 |
|
46 |
-
# Contenedor para historial de chat
|
47 |
if "history" not in st.session_state:
|
48 |
st.session_state.history = []
|
49 |
|
50 |
-
# Formulario para que el usuario ingrese oferta + nΓΊmero de perfiles
|
51 |
with st.form(key="oferta_form", clear_on_submit=False):
|
52 |
oferta = st.text_area("π° DescripciΓ³n de la oferta de empleo:", height=150)
|
53 |
num_perfiles = st.number_input(
|
@@ -56,24 +52,14 @@ with st.form(key="oferta_form", clear_on_submit=False):
|
|
56 |
)
|
57 |
enviar = st.form_submit_button(label="Enviar al agente")
|
58 |
|
59 |
-
# Cuando el usuario hace clic en βEnviarβ
|
60 |
if enviar and oferta:
|
61 |
-
# Agregamos el mensaje del usuario al historial
|
62 |
st.session_state.history.append(("usuario", oferta))
|
63 |
-
|
64 |
-
# Construimos el prompt tal como espera el agente: oferta + N
|
65 |
prompt = f"Oferta: {oferta}\nNΓΊmero perfiles: {num_perfiles}"
|
66 |
-
|
67 |
-
# Ejecutamos el agente de forma sΓncrona
|
68 |
-
# Runner.run_sync se encarga de bloquear hasta obtener la salida final
|
69 |
resultado = Runner.run_sync(agent, prompt)
|
70 |
respuesta = resultado.final_output
|
71 |
-
|
72 |
-
# Agregamos la respuesta del agente al historial
|
73 |
st.session_state.history.append(("agente", respuesta))
|
74 |
|
75 |
-
|
76 |
-
st.markdown("""---""")
|
77 |
st.markdown("### π¬ Historial de Chat")
|
78 |
for quien, texto in st.session_state.history:
|
79 |
if quien == "usuario":
|
@@ -81,6 +67,5 @@ for quien, texto in st.session_state.history:
|
|
81 |
else:
|
82 |
st.markdown(f"**Agente:** {texto}")
|
83 |
|
84 |
-
# Al pie, sugerimos al usuario limpiar el historial si desea volver a empezar
|
85 |
if st.button("π Limpiar historial"):
|
86 |
st.session_state.history = []
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
|
4 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
5 |
+
# 1) Reasignar HOME a /tmp para que ~/.streamlit pase a /tmp/.streamlit (es escribible)
|
6 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
7 |
+
os.environ["HOME"] = "/tmp" # ahora "~" = "/tmp"
|
8 |
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
|
|
|
9 |
try:
|
10 |
os.makedirs("/tmp/.streamlit", exist_ok=True)
|
11 |
except Exception:
|
12 |
+
# Si por alguna razΓ³n ya existe o no se puede crear, simplemente seguimos adelante.
|
13 |
pass
|
14 |
|
15 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
16 |
+
# 2) Asegurar que Python encuentre los paquetes agent/ y tools/
|
17 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
18 |
+
HERE = os.path.dirname(__file__) # normalmente /app/src
|
19 |
if HERE not in sys.path:
|
20 |
sys.path.insert(0, HERE)
|
21 |
|
22 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
23 |
+
# 3) Importar todo lo demΓ‘s (incluyendo Streamlit)
|
24 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
25 |
import streamlit as st
|
26 |
from agent.linkedin_agent import create_agent
|
27 |
from tools.web_search_tool import get_web_search_tool
|
28 |
from agents import Runner
|
29 |
|
30 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
31 |
+
# 4) ConfiguraciΓ³n de Streamlit y lΓ³gica de la app
|
32 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
33 |
st.set_page_config(page_title="Buscador de Perfiles LinkedIn", layout="centered")
|
34 |
|
|
|
35 |
if not os.getenv("OPENAI_API_KEY"):
|
36 |
+
st.error("β Por favor define el secret OPENAI_API_KEY en Settings β Secrets de tu Space.")
|
37 |
st.stop()
|
38 |
|
|
|
39 |
agent = create_agent()
|
40 |
|
41 |
+
st.title("π Buscador de Perfiles LinkedIn")
|
42 |
st.write("Ingresa la descripciΓ³n de la oferta y la cantidad de perfiles que deseas encontrar.")
|
43 |
|
|
|
44 |
if "history" not in st.session_state:
|
45 |
st.session_state.history = []
|
46 |
|
|
|
47 |
with st.form(key="oferta_form", clear_on_submit=False):
|
48 |
oferta = st.text_area("π° DescripciΓ³n de la oferta de empleo:", height=150)
|
49 |
num_perfiles = st.number_input(
|
|
|
52 |
)
|
53 |
enviar = st.form_submit_button(label="Enviar al agente")
|
54 |
|
|
|
55 |
if enviar and oferta:
|
|
|
56 |
st.session_state.history.append(("usuario", oferta))
|
|
|
|
|
57 |
prompt = f"Oferta: {oferta}\nNΓΊmero perfiles: {num_perfiles}"
|
|
|
|
|
|
|
58 |
resultado = Runner.run_sync(agent, prompt)
|
59 |
respuesta = resultado.final_output
|
|
|
|
|
60 |
st.session_state.history.append(("agente", respuesta))
|
61 |
|
62 |
+
st.markdown("---")
|
|
|
63 |
st.markdown("### π¬ Historial de Chat")
|
64 |
for quien, texto in st.session_state.history:
|
65 |
if quien == "usuario":
|
|
|
67 |
else:
|
68 |
st.markdown(f"**Agente:** {texto}")
|
69 |
|
|
|
70 |
if st.button("π Limpiar historial"):
|
71 |
st.session_state.history = []
|