File size: 2,727 Bytes
3495761
 
 
 
 
 
 
 
5424273
b09080a
 
5424273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b09080a
 
 
 
5424273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b09080a
5424273
 
 
 
 
 
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
import sys, os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
UTILS_DIR = os.path.join(BASE_DIR, "utils")

if UTILS_DIR not in sys.path:
    sys.path.insert(0, UTILS_DIR)

import streamlit as st
import requests
import sys, os

# ─── Ensure utils/ is importable ──────────────────────────────
UTILS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if UTILS_PATH not in sys.path:
    sys.path.append(UTILS_PATH)

from utils.backend import run_llm

st.title("🕵️ OSINT Skip-Trace AI Chatbot")
st.write("Search for a person, email, or domain and let AI summarize the OSINT results.")

# Init session state
if "skiptrace_chat" not in st.session_state:
    st.session_state.skiptrace_chat = []
if "skiptrace_output" not in st.session_state:
    st.session_state.skiptrace_output = []

# ─── OSINT Search Helper ──────────────────────────────────────
def run_osint_query(query: str) -> dict:
    """Perform lightweight OSINT searches (public endpoints + AI summary)."""
    results = []

    # Example: DuckDuckGo instant answers API
    try:
        url = f"https://api.duckduckgo.com/?q={query}&format=json&no_redirect=1&no_html=1"
        resp = requests.get(url, timeout=10).json()
        abstract = resp.get("AbstractText") or "No summary found."
        results.append(f"🔎 DuckDuckGo: {abstract}")
    except Exception as e:
        results.append(f"⚠️ DuckDuckGo error: {e}")

    # AI summarization
    ai_summary = run_llm(
        f"Provide an OSINT-style skip-trace summary for:\n{query}\n\nResults:\n" 
        + "\n".join(results)
    )

    return {
        "query": query,
        "raw_results": results,
        "ai_summary": ai_summary
    }

# ─── Chatbot UI ───────────────────────────────────────────────
for msg in st.session_state.skiptrace_chat:
    with st.chat_message(msg["role"]):
        st.markdown(msg["content"])

if prompt := st.chat_input("Enter a name, email, or domain to OSINT..."):
    st.session_state.skiptrace_chat.append({"role": "user", "content": prompt})
    with st.chat_message("user"):
        st.markdown(prompt)

    # Run OSINT + AI
    result = run_osint_query(prompt)
    reply = f"**AI Skip-Trace Summary for '{prompt}':**\n\n{result['ai_summary']}"

    with st.chat_message("assistant"):
        st.markdown(reply)

    # Save to state
    st.session_state.skiptrace_chat.append({"role": "assistant", "content": reply})
    st.session_state.skiptrace_output.append(result)