Spaces:
Sleeping
Sleeping
fix(env): Ahora aceptamos variables de entorno para las API KEYS
Browse files- src/app.py +27 -9
- src/custom_tools.py +6 -3
src/app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from incident_crew import IncidentReporterCrew
|
| 3 |
|
|
@@ -10,7 +12,10 @@ st.set_page_config(
|
|
| 10 |
|
| 11 |
# Inicializar el estado de la sesión para la API Key si no existe
|
| 12 |
if 'gemini_api_key' not in st.session_state:
|
| 13 |
-
st.session_state['gemini_api_key'] =
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
st.title("📄 Generador IA de Informes Post-Mortem")
|
|
@@ -20,19 +25,32 @@ with st.sidebar:
|
|
| 20 |
st.header("⚙️ Instrucciones")
|
| 21 |
|
| 22 |
# Campo de entrada para la API Key
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
if st.session_state['gemini_api_key']:
|
| 30 |
-
st.success("API Key cargada
|
| 31 |
else:
|
| 32 |
st.warning("🚨 Por favor, ingresa tu API Key de Gemini.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
st.write("
|
| 35 |
-
st.write("
|
| 36 |
|
| 37 |
|
| 38 |
# --- Formulario de entrada de datos principal ---
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
from incident_crew import IncidentReporterCrew
|
| 5 |
|
|
|
|
| 12 |
|
| 13 |
# Inicializar el estado de la sesión para la API Key si no existe
|
| 14 |
if 'gemini_api_key' not in st.session_state:
|
| 15 |
+
st.session_state['gemini_api_key'] = os.getenv("GEMINI_API_KEY", "")
|
| 16 |
+
|
| 17 |
+
if 'ipinfo_api_key' not in st.session_state:
|
| 18 |
+
st.session_state['ipinfo_api_key'] = os.getenv("IPINFO_API_KEY", "")
|
| 19 |
|
| 20 |
|
| 21 |
st.title("📄 Generador IA de Informes Post-Mortem")
|
|
|
|
| 25 |
st.header("⚙️ Instrucciones")
|
| 26 |
|
| 27 |
# Campo de entrada para la API Key
|
| 28 |
+
if not os.getenv("GEMINI_API_KEY"):
|
| 29 |
+
st.session_state['gemini_api_key'] = st.text_input(
|
| 30 |
+
"- 🔑 Ingresa tu API Key de Gemini",
|
| 31 |
+
type="password",
|
| 32 |
+
value=st.session_state['gemini_api_key']
|
| 33 |
+
)
|
| 34 |
|
| 35 |
if st.session_state['gemini_api_key']:
|
| 36 |
+
st.success("Gemini API Key cargada!")
|
| 37 |
else:
|
| 38 |
st.warning("🚨 Por favor, ingresa tu API Key de Gemini.")
|
| 39 |
+
|
| 40 |
+
if not os.getenv("IPINFO_API_KEY"):
|
| 41 |
+
st.session_state['ipinfo_api_key'] = st.text_input(
|
| 42 |
+
"- 🔑 Ingresa tu API Key de IPInfo",
|
| 43 |
+
type="password",
|
| 44 |
+
value=st.session_state['ipinfo_api_key']
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if st.session_state['ipinfo_api_key']:
|
| 48 |
+
st.success("IPInfo API Key cargada!")
|
| 49 |
+
else:
|
| 50 |
+
st.warning("🚨 Por favor, ingresa tu API Key de IPInfo.")
|
| 51 |
|
| 52 |
+
st.write("- 📄 Completa el formulario con los detalles de la incidencia")
|
| 53 |
+
st.write("- 🚀 Presiona el botón y la IA generará un informe técnico estructurado post-mortem de tu incidente.")
|
| 54 |
|
| 55 |
|
| 56 |
# --- Formulario de entrada de datos principal ---
|
src/custom_tools.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
import os
|
| 2 |
import requests
|
| 3 |
from crewai.tools import BaseTool
|
| 4 |
from typing import Type, List
|
| 5 |
from pydantic import BaseModel, Field
|
|
|
|
| 6 |
|
| 7 |
# --- 1. IPInfo Geo Lookup Tool ---
|
| 8 |
class IPInfoToolInput(BaseModel):
|
|
@@ -19,24 +19,27 @@ class IPInfoGeoLookup(BaseTool):
|
|
| 19 |
args_schema: Type[BaseModel] = IPInfoToolInput
|
| 20 |
|
| 21 |
def _run(self, target: List[str]) -> str:
|
| 22 |
-
api_key =
|
| 23 |
if not api_key:
|
| 24 |
return "Error: La variable de entorno IPINFO_APIKEY no está configurada."
|
| 25 |
|
| 26 |
results = []
|
|
|
|
| 27 |
for ip_address in target:
|
| 28 |
try:
|
| 29 |
url = f"https://api.ipinfo.io/lite/{ip_address}?token={api_key}"
|
| 30 |
response = requests.get(url)
|
| 31 |
-
response.raise_for_status()
|
| 32 |
data = response.json()
|
| 33 |
# Formateamos la salida para que sea legible y útil para el agente
|
| 34 |
result_str = (
|
| 35 |
f"IP: {data.get('ip')}, Country: {data.get('country')}, ASN: {data.get('as_name')}"
|
| 36 |
)
|
| 37 |
results.append(result_str)
|
|
|
|
| 38 |
except requests.exceptions.RequestException as e:
|
| 39 |
results.append(f"Error al consultar la IP {ip_address}: {e}")
|
|
|
|
| 40 |
return "\n".join(results)
|
| 41 |
|
| 42 |
# --- 2. VirusTotal Scanner Tool ---
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
from crewai.tools import BaseTool
|
| 3 |
from typing import Type, List
|
| 4 |
from pydantic import BaseModel, Field
|
| 5 |
+
import streamlit as st
|
| 6 |
|
| 7 |
# --- 1. IPInfo Geo Lookup Tool ---
|
| 8 |
class IPInfoToolInput(BaseModel):
|
|
|
|
| 19 |
args_schema: Type[BaseModel] = IPInfoToolInput
|
| 20 |
|
| 21 |
def _run(self, target: List[str]) -> str:
|
| 22 |
+
api_key = st.session_state['ipinfo_api_key']
|
| 23 |
if not api_key:
|
| 24 |
return "Error: La variable de entorno IPINFO_APIKEY no está configurada."
|
| 25 |
|
| 26 |
results = []
|
| 27 |
+
|
| 28 |
for ip_address in target:
|
| 29 |
try:
|
| 30 |
url = f"https://api.ipinfo.io/lite/{ip_address}?token={api_key}"
|
| 31 |
response = requests.get(url)
|
| 32 |
+
response.raise_for_status()
|
| 33 |
data = response.json()
|
| 34 |
# Formateamos la salida para que sea legible y útil para el agente
|
| 35 |
result_str = (
|
| 36 |
f"IP: {data.get('ip')}, Country: {data.get('country')}, ASN: {data.get('as_name')}"
|
| 37 |
)
|
| 38 |
results.append(result_str)
|
| 39 |
+
|
| 40 |
except requests.exceptions.RequestException as e:
|
| 41 |
results.append(f"Error al consultar la IP {ip_address}: {e}")
|
| 42 |
+
|
| 43 |
return "\n".join(results)
|
| 44 |
|
| 45 |
# --- 2. VirusTotal Scanner Tool ---
|