Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import asyncio | |
| from search_engine import search, advanced_search | |
| from osint_engine import create_report | |
| import time | |
| 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, | |
| name=None, address=None, progress=gr.Progress()): | |
| """Safe wrapper for search functions""" | |
| try: | |
| kwargs = { | |
| "max_results": max_results, | |
| "platform": platform, | |
| "phone": phone, | |
| "location": location, | |
| "domain": domain, | |
| "name": name, | |
| "address": address | |
| } | |
| progress(0, desc="Initializing search...") | |
| time.sleep(0.5) # Show loading state | |
| if search_type == "web": | |
| progress(0.3, desc="Searching web...") | |
| results = search(query, max_results) | |
| else: | |
| # For async searches | |
| if search_type == "image" and image_url: | |
| query = image_url | |
| progress(0.5, desc=f"Performing {search_type} search...") | |
| loop = asyncio.new_event_loop() | |
| asyncio.set_event_loop(loop) | |
| results = loop.run_until_complete(advanced_search(query, search_type, **kwargs)) | |
| loop.close() | |
| progress(0.8, desc="Processing results...") | |
| time.sleep(0.5) # Show processing state | |
| progress(1.0, desc="Done!") | |
| 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", variant="primary") | |
| results_output = gr.Markdown(label="Search Results") | |
| search_button.click( | |
| fn=safe_search, | |
| inputs=[query_input, gr.State("web"), max_results], | |
| outputs=results_output, | |
| show_progress=True | |
| ) | |
| with gr.Tab("Username Search"): | |
| username_input = gr.Textbox( | |
| label="Username", | |
| placeholder="Enter username to search..." | |
| ) | |
| username_button = gr.Button("π Search Username", variant="primary") | |
| username_output = gr.Markdown(label="Username Search Results") | |
| username_button.click( | |
| fn=safe_search, | |
| inputs=[username_input, gr.State("username")], | |
| outputs=username_output, | |
| show_progress=True | |
| ) | |
| with gr.Tab("Image Search"): | |
| with gr.Row(): | |
| image_url = gr.Textbox( | |
| label="Image URL", | |
| placeholder="Enter image URL to search..." | |
| ) | |
| image_upload = gr.Image( | |
| label="Or Upload Image", | |
| type="filepath" | |
| ) | |
| image_button = gr.Button("π Search Image", variant="primary") | |
| image_output = gr.Markdown(label="Image Search Results") | |
| def handle_image_search(url, uploaded_image): | |
| if uploaded_image: | |
| return safe_search(uploaded_image, "image", image_url=uploaded_image) | |
| return safe_search(url, "image", image_url=url) | |
| image_button.click( | |
| fn=handle_image_search, | |
| inputs=[image_url, image_upload], | |
| outputs=image_output, | |
| show_progress=True | |
| ) | |
| with gr.Tab("Social Media Search"): | |
| with gr.Row(): | |
| social_username = gr.Textbox( | |
| label="Username", | |
| placeholder="Enter username..." | |
| ) | |
| platform = gr.Dropdown( | |
| choices=[ | |
| "all", "twitter", "instagram", "facebook", "linkedin", | |
| "github", "reddit", "youtube", "tiktok", "pinterest", | |
| "snapchat", "twitch", "medium", "devto", "stackoverflow" | |
| ], | |
| value="all", | |
| label="Platform" | |
| ) | |
| social_button = gr.Button("π Search Social Media", variant="primary") | |
| social_output = gr.Markdown(label="Social Media Results") | |
| social_button.click( | |
| fn=safe_search, | |
| inputs=[social_username, gr.State("social"), gr.State(5), platform], | |
| outputs=social_output, | |
| show_progress=True | |
| ) | |
| with gr.Tab("Personal Info"): | |
| with gr.Group(): | |
| with gr.Row(): | |
| name = gr.Textbox(label="Full Name", placeholder="John Doe") | |
| address = gr.Textbox(label="Address/Location", placeholder="City, Country") | |
| initial_search = gr.Button("π Find Possible Matches", variant="primary") | |
| matches_output = gr.Markdown(label="Possible Matches") | |
| with gr.Row(visible=False) as details_row: | |
| selected_person = gr.Dropdown( | |
| choices=[], | |
| label="Select Person", | |
| interactive=True | |
| ) | |
| details_button = gr.Button("π Get Detailed Info", variant="secondary") | |
| details_output = gr.Markdown(label="Detailed Information") | |
| def find_matches(name, address): | |
| return safe_search(name, "personal", name=name, location=address) | |
| def get_details(person): | |
| if not person: | |
| return "Please select a person first." | |
| return safe_search(person, "personal", name=person) | |
| initial_search.click( | |
| fn=find_matches, | |
| inputs=[name, address], | |
| outputs=matches_output | |
| ).then( | |
| lambda: gr.Row(visible=True), | |
| None, | |
| details_row | |
| ) | |
| details_button.click( | |
| fn=get_details, | |
| inputs=[selected_person], | |
| outputs=details_output, | |
| show_progress=True | |
| ) | |
| 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", variant="primary") | |
| historical_output = gr.Markdown(label="Historical Data Results") | |
| historical_button.click( | |
| fn=safe_search, | |
| inputs=[url_input, gr.State("historical")], | |
| outputs=historical_output, | |
| show_progress=True | |
| ) | |
| 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 | |
| - Personal Info: "John Smith" in "New York, USA" | |
| - Historical Data: "example.com" | |
| """) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() | |