File size: 8,717 Bytes
dcc91e6
12d42ff
 
 
dcc91e6
12d42ff
 
 
dcc91e6
12d42ff
 
 
dcc91e6
 
 
 
 
 
 
 
 
 
 
12d42ff
 
71e076d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12d42ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcc91e6
 
 
 
12d42ff
 
 
 
dcc91e6
 
12d42ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71e076d
12d42ff
 
 
 
 
 
 
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import gradio as gr
import asyncio
from search_engine import search, advanced_search
from osint_engine import create_report

def format_results(results):
    if not results:
        return "No results found."
        
    if isinstance(results, list):
        # Format web search results
        formatted_results = []
        for result in results:
            formatted_result = f"""
### [{result['title']}]({result['url']})

{result['summary']}

**Source:** {result['url']}
**Published:** {result.get('published_date', 'N/A')}
            """
            formatted_results.append(formatted_result)
        return "\n---\n".join(formatted_results)
    elif isinstance(results, dict):
        # Format OSINT results
        if "error" in results:
            return f"Error: {results['error']}"
            
        formatted = []
        
        # Web results
        if "web" in results:
            formatted.append(format_results(results["web"]))
        
        # Username/Platform results
        if "platforms" in results:
            platforms = results["platforms"]
            if platforms:
                formatted.append("\n### πŸ” Platform Results\n")
                for platform in platforms:
                    formatted.append(f"""
- **Platform:** {platform['platform']}
  **URL:** [{platform['url']}]({platform['url']})
  **Status:** {'Found βœ…' if platform.get('exists', False) else 'Not Found ❌'}
""")
                    
        # Image analysis
        if "analysis" in results:
            analysis = results["analysis"]
            if analysis:
                formatted.append("\n### πŸ–ΌοΈ Image Analysis\n")
                for key, value in analysis.items():
                    formatted.append(f"- **{key.title()}:** {value}")
                    
        # Similar images
        if "similar_images" in results:
            similar = results["similar_images"]
            if similar:
                formatted.append("\n### πŸ” Similar Images\n")
                for img in similar:
                    formatted.append(f"- [{img['source']}]({img['url']})")
                    
        # Location info
        if "location" in results:
            location = results["location"]
            if location and not isinstance(location, str):
                formatted.append("\n### πŸ“ Location Information\n")
                for key, value in location.items():
                    if key != 'raw':
                        formatted.append(f"- **{key.title()}:** {value}")
                        
        # Domain info
        if "domain" in results:
            domain = results["domain"]
            if domain and not isinstance(domain, str):
                formatted.append("\n### 🌐 Domain Information\n")
                for key, value in domain.items():
                    formatted.append(f"- **{key.title()}:** {value}")
                    
        # Historical data
        if "historical" in results:
            historical = results["historical"]
            if historical:
                formatted.append("\n### πŸ“… Historical Data\n")
                for entry in historical[:5]:  # Limit to 5 entries
                    formatted.append(f"""
- **Date:** {entry.get('timestamp', 'N/A')}
  **URL:** [{entry.get('url', 'N/A')}]({entry.get('url', '#')})
  **Type:** {entry.get('mime_type', 'N/A')}
""")
        
        return "\n".join(formatted) if formatted else "No relevant information found."
    else:
        return str(results)

def safe_search(query, search_type="web", max_results=5, platform=None, 
                image_url=None, phone=None, location=None, domain=None):
    """Safe wrapper for search functions"""
    try:
        kwargs = {
            "max_results": max_results,
            "platform": platform,
            "phone": phone,
            "location": location,
            "domain": domain
        }
        
        if search_type == "web":
            results = search(query, max_results)
        else:
            # For async searches
            if search_type == "image" and image_url:
                query = image_url
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            results = loop.run_until_complete(advanced_search(query, search_type, **kwargs))
            loop.close()
            
        return format_results(results)
    except Exception as e:
        return f"Error: {str(e)}"

# Create Gradio interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# πŸ” Intelligent Search Engine")
    gr.Markdown("""
    An AI-powered search engine with advanced OSINT capabilities.
    
    Features:
    - Web search with AI summaries
    - Username search across platforms
    - Image search and analysis
    - Social media profile search
    - Personal information gathering
    - Historical data search
    """)
    
    with gr.Tab("Web Search"):
        with gr.Row():
            query_input = gr.Textbox(
                label="Search Query",
                placeholder="Enter your search query...",
                lines=2
            )
            max_results = gr.Slider(
                minimum=1,
                maximum=10,
                value=5,
                step=1,
                label="Number of Results"
            )
        search_button = gr.Button("Search")
        results_output = gr.Markdown(label="Search Results")
        search_button.click(
            fn=lambda q, n: safe_search(q, "web", n),
            inputs=[query_input, max_results],
            outputs=results_output
        )
        
    with gr.Tab("Username Search"):
        username_input = gr.Textbox(
            label="Username",
            placeholder="Enter username to search..."
        )
        username_button = gr.Button("Search Username")
        username_output = gr.Markdown(label="Username Search Results")
        username_button.click(
            fn=lambda u: safe_search(u, "username"),
            inputs=username_input,
            outputs=username_output
        )
        
    with gr.Tab("Image Search"):
        image_url = gr.Textbox(
            label="Image URL",
            placeholder="Enter image URL to search..."
        )
        image_button = gr.Button("Search Image")
        image_output = gr.Markdown(label="Image Search Results")
        image_button.click(
            fn=lambda u: safe_search(u, "image", image_url=u),
            inputs=image_url,
            outputs=image_output
        )
        
    with gr.Tab("Social Media Search"):
        with gr.Row():
            social_username = gr.Textbox(
                label="Username",
                placeholder="Enter username..."
            )
            platform = gr.Dropdown(
                choices=["all", "instagram", "twitter", "reddit"],
                value="all",
                label="Platform"
            )
        social_button = gr.Button("Search Social Media")
        social_output = gr.Markdown(label="Social Media Results")
        social_button.click(
            fn=lambda u, p: safe_search(u, "social", platform=p),
            inputs=[social_username, platform],
            outputs=social_output
        )
        
    with gr.Tab("Personal Info"):
        with gr.Row():
            phone = gr.Textbox(label="Phone Number", placeholder="+1234567890")
            location = gr.Textbox(label="Location", placeholder="City, Country")
            domain = gr.Textbox(label="Domain", placeholder="example.com")
        personal_button = gr.Button("Gather Information")
        personal_output = gr.Markdown(label="Personal Information Results")
        personal_button.click(
            fn=lambda p, l, d: safe_search("", "personal", phone=p, location=l, domain=d),
            inputs=[phone, location, domain],
            outputs=personal_output
        )
        
    with gr.Tab("Historical Data"):
        url_input = gr.Textbox(
            label="URL",
            placeholder="Enter URL to search historical data..."
        )
        historical_button = gr.Button("Search Historical Data")
        historical_output = gr.Markdown(label="Historical Data Results")
        historical_button.click(
            fn=lambda u: safe_search(u, "historical"),
            inputs=url_input,
            outputs=historical_output
        )
        
    gr.Markdown("""
    ### Examples
    Try these example searches:
    - Web Search: "Latest developments in artificial intelligence"
    - Username: "johndoe"
    - Image URL: "https://images.app.goo.gl/w5BtxZKvzg6BdkGE8"
    - Social Media: "techuser" on Twitter
    - Historical Data: "example.com"
    """)

# Launch the app
if __name__ == "__main__":
    demo.launch()