Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +28 -17
src/streamlit_app.py
CHANGED
@@ -1,39 +1,46 @@
|
|
1 |
import os
|
2 |
import sys
|
|
|
3 |
|
4 |
-
#
|
5 |
-
#
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
17 |
-
#
|
18 |
-
HERE = os.path.dirname(__file__)
|
19 |
if HERE not in sys.path:
|
20 |
sys.path.insert(0, HERE)
|
21 |
|
22 |
-
#
|
23 |
-
# 3)
|
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)
|
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("❌
|
37 |
st.stop()
|
38 |
|
39 |
agent = create_agent()
|
@@ -47,7 +54,7 @@ if "history" not in st.session_state:
|
|
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(
|
50 |
-
"🔢 Cantidad de perfiles a buscar:",
|
51 |
min_value=1, max_value=20, value=5
|
52 |
)
|
53 |
enviar = st.form_submit_button(label="Enviar al agente")
|
@@ -55,6 +62,10 @@ with st.form(key="oferta_form", clear_on_submit=False):
|
|
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))
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
+
import asyncio
|
4 |
|
5 |
+
# ───────────────────────────────────────────────────
|
6 |
+
# 0) Crear y setear un event loop en este hilo (ScriptRunner.scriptThread)
|
7 |
+
# ───────────────────────────────────────────────────
|
8 |
+
loop = asyncio.new_event_loop()
|
9 |
+
asyncio.set_event_loop(loop)
|
10 |
+
|
11 |
+
# ───────────────────────────────────────────────────
|
12 |
+
# 1) Redirigir la configuración de Streamlit a /tmp/.streamlit
|
13 |
+
# (para no chocar con permisos en '/.streamlit' en HF Spaces)
|
14 |
+
# ───────────────────────────────────────────────────
|
15 |
+
os.environ["HOME"] = "/tmp"
|
16 |
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
|
17 |
try:
|
18 |
os.makedirs("/tmp/.streamlit", exist_ok=True)
|
19 |
except Exception:
|
|
|
20 |
pass
|
21 |
|
22 |
+
# ───────────────────────────────────────────────────
|
23 |
+
# 2) Asegurar que Python pueda encontrar src/ → agent/ y tools/
|
24 |
+
# ───────────────────────────────────────────────────
|
25 |
+
HERE = os.path.dirname(__file__) # '/app/src'
|
26 |
if HERE not in sys.path:
|
27 |
sys.path.insert(0, HERE)
|
28 |
|
29 |
+
# ───────────────────────────────────────────────────
|
30 |
+
# 3) Ahora sí importamos Streamlit y el resto
|
31 |
+
# ───────────────────────────────────────────────────
|
32 |
import streamlit as st
|
33 |
from agent.linkedin_agent import create_agent
|
34 |
from tools.web_search_tool import get_web_search_tool
|
35 |
from agents import Runner
|
36 |
|
37 |
+
# ───────────────────────────────────────────────────
|
38 |
+
# 4) Resto de tu código Streamlit…
|
39 |
+
# ───────────────────────────────────────────────────
|
40 |
st.set_page_config(page_title="Buscador de Perfiles LinkedIn", layout="centered")
|
41 |
|
42 |
if not os.getenv("OPENAI_API_KEY"):
|
43 |
+
st.error("❌ Define el secret OPENAI_API_KEY en Settings → Secrets de tu Space.")
|
44 |
st.stop()
|
45 |
|
46 |
agent = create_agent()
|
|
|
54 |
with st.form(key="oferta_form", clear_on_submit=False):
|
55 |
oferta = st.text_area("📰 Descripción de la oferta de empleo:", height=150)
|
56 |
num_perfiles = st.number_input(
|
57 |
+
"🔢 Cantidad de perfiles a buscar:",
|
58 |
min_value=1, max_value=20, value=5
|
59 |
)
|
60 |
enviar = st.form_submit_button(label="Enviar al agente")
|
|
|
62 |
if enviar and oferta:
|
63 |
st.session_state.history.append(("usuario", oferta))
|
64 |
prompt = f"Oferta: {oferta}\nNúmero perfiles: {num_perfiles}"
|
65 |
+
|
66 |
+
# ───────────────────────────────────────────────────
|
67 |
+
# Aquí ya existe un event loop, así que run_sync no fallará
|
68 |
+
# ───────────────────────────────────────────────────
|
69 |
resultado = Runner.run_sync(agent, prompt)
|
70 |
respuesta = resultado.final_output
|
71 |
st.session_state.history.append(("agente", respuesta))
|