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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
SearXNG Deep Research - Multi-Modal Multi-Media Search & Scrape System
|
| 3 |
+
Fully Customizable & Automated Reconfigured with Uncensored Deep Research
|
| 4 |
+
|
| 5 |
+
Built with anycoder - https://huggingface.co/spaces/akhaliq/anycoder
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import json
|
| 10 |
+
import time
|
| 11 |
+
import os
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
from typing import Optional, Dict, List, Any
|
| 14 |
+
from dataclasses import dataclass, field
|
| 15 |
+
import asyncio
|
| 16 |
+
|
| 17 |
+
# Import required libraries for search and scraping
|
| 18 |
+
try:
|
| 19 |
+
import httpx
|
| 20 |
+
import aiohttp
|
| 21 |
+
HAS_ASYNC = True
|
| 22 |
+
except ImportError:
|
| 23 |
+
HAS_ASYNC = False
|
| 24 |
+
|
| 25 |
+
# ============================================================
|
| 26 |
+
# Configuration & Constants
|
| 27 |
+
# ============================================================
|
| 28 |
+
|
| 29 |
+
@dataclass
|
| 30 |
+
class SearchConfig:
|
| 31 |
+
"""Configuration for search parameters"""
|
| 32 |
+
# Search Engine Settings
|
| 33 |
+
engines: List[str] = field(default_factory=lambda: [
|
| 34 |
+
"google", "bing", "duckduckgo", "yahoo", "baidu",
|
| 35 |
+
"yandex", "searx", "qwant", "startpage", "ecosia"
|
| 36 |
+
])
|
| 37 |
+
|
| 38 |
+
# Content Filters
|
| 39 |
+
safe_search: int = 2 # 0=off, 1=moderate, 2=strict
|
| 40 |
+
language: str = "en"
|
| 41 |
+
region: str = "us-en"
|
| 42 |
+
|
| 43 |
+
# Result Settings
|
| 44 |
+
max_results: int = 50
|
| 45 |
+
time_range: str = "any" # day, week, month, year, any
|
| 46 |
+
sort_by: str = "relevance" # relevance, date, quality
|
| 47 |
+
|
| 48 |
+
# Content Types
|
| 49 |
+
include_text: bool = True
|
| 50 |
+
include_images: bool = True
|
| 51 |
+
include_videos: bool = True
|
| 52 |
+
include_audio: bool = True
|
| 53 |
+
include_documents: bool = True
|
| 54 |
+
include_news: bool = True
|
| 55 |
+
include_social: bool = True
|
| 56 |
+
|
| 57 |
+
# Deep Research Settings
|
| 58 |
+
research_depth: int = 3 # How deep to dig
|
| 59 |
+
auto_cite: bool = True
|
| 60 |
+
extract_metadata: bool = True
|
| 61 |
+
follow_redirects: bool = True
|
| 62 |
+
|
| 63 |
+
# ============================================================
|
| 64 |
+
# Core Search & Research Functions
|
| 65 |
+
# ============================================================
|
| 66 |
+
|
| 67 |
+
class DeepResearchEngine:
|
| 68 |
+
"""
|
| 69 |
+
Multi-modal multi-media search/scrape engine with uncensored deep research
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
def __init__(self):
|
| 73 |
+
self.config = SearchConfig()
|
| 74 |
+
self.session = None
|
| 75 |
+
self.search_history = []
|
| 76 |
+
|
| 77 |
+
async def _get_session(self):
|
| 78 |
+
"""Get or create async session"""
|
| 79 |
+
if self.session is None:
|
| 80 |
+
self.session = httpx.AsyncClient(
|
| 81 |
+
timeout=30.0,
|
| 82 |
+
follow_redirects=True,
|
| 83 |
+
headers={
|
| 84 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
| 85 |
+
}
|
| 86 |
+
)
|
| 87 |
+
return self.session
|
| 88 |
+
|
| 89 |
+
def search_web(
|
| 90 |
+
self,
|
| 91 |
+
query: str,
|
| 92 |
+
engines: List[str] = None,
|
| 93 |
+
max_results: int = 20,
|
| 94 |
+
time_range: str = "any",
|
| 95 |
+
content_types: Dict[str, bool] = None,
|
| 96 |
+
**kwargs
|
| 97 |
+
) -> Dict[str, Any]:
|
| 98 |
+
"""
|
| 99 |
+
Perform web search across multiple engines
|
| 100 |
+
"""
|
| 101 |
+
if content_types is None:
|
| 102 |
+
content_types = {
|
| 103 |
+
"text": True,
|
| 104 |
+
"images": True,
|
| 105 |
+
"videos": True,
|
| 106 |
+
"audio": True,
|
| 107 |
+
"documents": True
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
# Simulate search results (in production, integrate with actual search APIs)
|
| 111 |
+
results = {
|
| 112 |
+
"query": query,
|
| 113 |
+
"timestamp": datetime.now().isoformat(),
|
| 114 |
+
"total_results": max_results,
|
| 115 |
+
"results": [],
|
| 116 |
+
"images": [],
|
| 117 |
+
"videos": [],
|
| 118 |
+
"audio": [],
|
| 119 |
+
"documents": [],
|
| 120 |
+
"sources": [],
|
| 121 |
+
"metadata": {
|
| 122 |
+
"engines_used": engines or self.config.engines,
|
| 123 |
+
"time_range": time_range,
|
| 124 |
+
"content_types": content_types
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
# Generate comprehensive search results
|
| 129 |
+
search_terms = query.split()
|
| 130 |
+
base_results = [
|
| 131 |
+
{
|
| 132 |
+
"title": f"Comprehensive Analysis: {' '.join(search_terms[:min(3, len(search_terms))])} - Deep Research Report",
|
| 133 |
+
"url": f"https://research.example.com/{'-'.join(search_terms[:2])}.html",
|
| 134 |
+
"snippet": f"This comprehensive report examines multiple facets of {query}, "
|
| 135 |
+
f"including historical context, current developments, and future implications.",
|
| 136 |
+
"source": "research-article",
|
| 137 |
+
"relevance_score": 0.98,
|
| 138 |
+
"date": "2024-01-15",
|
| 139 |
+
"content_type": "text",
|
| 140 |
+
"domain": "research.example.com",
|
| 141 |
+
"citation": "Smith, J. (2024). Comprehensive Analysis. Journal of Research.",
|
| 142 |
+
"metadata": {
|
| 143 |
+
"word_count": 5000,
|
| 144 |
+
"authors": ["Dr. Jane Smith", "Prof. John Doe"],
|
| 145 |
+
"doi": "10.1234/research.2024.001"
|
| 146 |
+
}
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"title": f"Latest News & Updates: {' '.join(search_terms[:min(2, len(search_terms))])}",
|
| 150 |
+
"url": f"https://news.example.com/{'-'.join(search_terms[:2])}-latest",
|
| 151 |
+
"snippet": f"Stay updated with the latest developments in {query}. "
|
| 152 |
+
f"Breaking news, analysis, and expert commentary from around the globe.",
|
| 153 |
+
"source": "news",
|
| 154 |
+
"relevance_score": 0.95,
|
| 155 |
+
"date": "2024-01-14",
|
| 156 |
+
"content_type": "text",
|
| 157 |
+
"domain": "news.example.com",
|
| 158 |
+
"citation": "News Desk. (2024). Latest Updates. Global News Network.",
|
| 159 |
+
"metadata": {
|
| 160 |
+
"category": "Technology",
|
| 161 |
+
"read_time": "5 min"
|
| 162 |
+
}
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"title": f"Technical Documentation: {' '.join(search_terms[:min(3, len(search_terms))]} - Complete Guide",
|
| 166 |
+
"url": f"https://docs.example.com/{'-'.join(search_terms[:2])}-guide",
|
| 167 |
+
"snippet": f"Official technical documentation and implementation guide for {query}. "
|
| 168 |
+
f"Includes code examples, best practices, and advanced techniques.",
|
| 169 |
+
"source": "documentation",
|
| 170 |
+
"relevance_score": 0.93,
|
| 171 |
+
"date": "2024-01-10",
|
| 172 |
+
"content_type": "text",
|
| 173 |
+
"domain": "docs.example.com",
|
| 174 |
+
"citation": "Documentation Team. (2024). Technical Guide. Official Docs.",
|
| 175 |
+
"metadata": {
|
| 176 |
+
"version": "2.1.0",
|
| 177 |
+
"last_updated": "2024-01-10"
|
| 178 |
+
}
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"title": f"Academic Research Paper: Statistical Analysis of {' '.join(search_terms[:min(2, len(search_terms))])}",
|
| 182 |
+
"url": f"https://academic.example.edu/papers/{'-'.join(search_terms[:2])}-analysis",
|
| 183 |
+
"snippet": f"Peer-reviewed academic research presenting statistical analysis and "
|
| 184 |
+
f"empirical findings related to {query}.",
|
| 185 |
+
"source": "academic",
|
| 186 |
+
"relevance_score": 0.91,
|
| 187 |
+
"date": "2024-01-08",
|
| 188 |
+
"content_type": "text",
|
| 189 |
+
"domain": "academic.example.edu",
|
| 190 |
+
"citation": "Doe, A. & Brown, B. (2024). Statistical Analysis. Journal of Data Science.",
|
| 191 |
+
"metadata": {
|
| 192 |
+
"peer_reviewed": True,
|
| 193 |
+
"citations": 47,
|
| 194 |
+
"methodology": "Quantitative"
|
| 195 |
+
}
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
"title": f"Community Discussion: Open Forum on {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 199 |
+
"url": f"https://community.example.com/threads/{'-'.join(search_terms[:2])}-discussion",
|
| 200 |
+
"snippet": f"Open community discussion covering various perspectives and user experiences "
|
| 201 |
+
f"related to {query}. Includes polls and community voting.",
|
| 202 |
+
"source": "forum",
|
| 203 |
+
"relevance_score": 0.88,
|
| 204 |
+
"date": "2024-01-12",
|
| 205 |
+
"content_type": "text",
|
| 206 |
+
"domain": "community.example.com",
|
| 207 |
+
"citation": "Community Members. (2024). Discussion Thread. Online Forum.",
|
| 208 |
+
"metadata": {
|
| 209 |
+
"posts": 156,
|
| 210 |
+
"views": 12500
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
]
|
| 214 |
+
|
| 215 |
+
# Generate additional results based on content types
|
| 216 |
+
if content_types.get("images", True):
|
| 217 |
+
results["images"] = [
|
| 218 |
+
{
|
| 219 |
+
"title": f"{query.title()} - Featured Image",
|
| 220 |
+
"url": f"https://images.example.com/{'-'.join(search_terms[:2])}.jpg",
|
| 221 |
+
"thumbnail": f"https://images.example.com/thumb/{'-'.join(search_terms[:2])}-thumb.jpg",
|
| 222 |
+
"source": "Stock Photo Library",
|
| 223 |
+
"resolution": "4000x3000",
|
| 224 |
+
"license": "Creative Commons",
|
| 225 |
+
"relevance_score": 0.92
|
| 226 |
+
},
|
| 227 |
+
{
|
| 228 |
+
"title": f"Infographic: {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 229 |
+
"url": f"https://images.example.com/infographics/{'-'.join(search_terms[:2])}.png",
|
| 230 |
+
"thumbnail": f"https://images.example.com/thumb/infographic-{'-'.join(search_terms[:2])}.png",
|
| 231 |
+
"source": "InfoGraphics Hub",
|
| 232 |
+
"resolution": "1920x1080",
|
| 233 |
+
"license": "Royalty Free",
|
| 234 |
+
"relevance_score": 0.89
|
| 235 |
+
}
|
| 236 |
+
]
|
| 237 |
+
|
| 238 |
+
if content_types.get("videos", True):
|
| 239 |
+
results["videos"] = [
|
| 240 |
+
{
|
| 241 |
+
"title": f"Complete Tutorial: {' '.join(search_terms[:min(4, len(search_terms))]} - Full Course",
|
| 242 |
+
"url": f"https://video.example.com/watch/{'-'.join(search_terms[:2])}-tutorial",
|
| 243 |
+
"thumbnail": f"https://video.example.com/thumb/{'-'.join(search_terms[:2])}.jpg",
|
| 244 |
+
"source": "Educational Platform",
|
| 245 |
+
"duration": "2:45:30",
|
| 246 |
+
"quality": "4K",
|
| 247 |
+
"views": 125000,
|
| 248 |
+
"relevance_score": 0.94
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"title": f"Latest Documentary: {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 252 |
+
"url": f"https://video.example.com/documentary/{'-'.join(search_terms[:2])}",
|
| 253 |
+
"thumbnail": f"https://video.example.com/thumb/doc-{'-'.join(search_terms[:2])}.jpg",
|
| 254 |
+
"source": "Documentary Channel",
|
| 255 |
+
"duration": "58:00",
|
| 256 |
+
"quality": "HD",
|
| 257 |
+
"relevance_score": 0.87
|
| 258 |
+
}
|
| 259 |
+
]
|
| 260 |
+
|
| 261 |
+
if content_types.get("audio", True):
|
| 262 |
+
results["audio"] = [
|
| 263 |
+
{
|
| 264 |
+
"title": f"Podcast Episode: Deep Dive into {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 265 |
+
"url": f"https://audio.example.com/podcast/{'-'.join(search_terms[:2])}.mp3",
|
| 266 |
+
"source": "Research Podcast Network",
|
| 267 |
+
"duration": "45:30",
|
| 268 |
+
"episode": 127,
|
| 269 |
+
"relevance_score": 0.86
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"title": f"Audiobook Chapter: The Complete Guide to {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 273 |
+
"url": f"https://audio.example.com/audiobook/{'-'.join(search_terms[:2])}.mp3",
|
| 274 |
+
"source": "Audiobook Publisher",
|
| 275 |
+
"duration": "3:20:00",
|
| 276 |
+
"chapter": 12,
|
| 277 |
+
"relevance_score": 0.83
|
| 278 |
+
}
|
| 279 |
+
]
|
| 280 |
+
|
| 281 |
+
if content_types.get("documents", True):
|
| 282 |
+
results["documents"] = [
|
| 283 |
+
{
|
| 284 |
+
"title": f"White Paper: Strategic Analysis of {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 285 |
+
"url": f"https://docs.example.com/whitepapers/{'-'.join(search_terms[:2])}.pdf",
|
| 286 |
+
"source": "Industry Research Firm",
|
| 287 |
+
"pages": 45,
|
| 288 |
+
"format": "PDF",
|
| 289 |
+
"relevance_score": 0.90
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"title": f"Technical Report: Implementation Guidelines for {' '.join(search_terms[:min(3, len(search_terms))]}",
|
| 293 |
+
"url": f"https://docs.example.com/reports/{'-'.join(search_terms[:2])}-report.pdf",
|
| 294 |
+
"source": "Technical Standards Body",
|
| 295 |
+
"pages": 78,
|
| 296 |
+
"format": "PDF",
|
| 297 |
+
"relevance_score": 0.88
|
| 298 |
+
}
|
| 299 |
+
]
|
| 300 |
+
|
| 301 |
+
# Compile results
|
| 302 |
+
all_results = base_results[:max_results]
|
| 303 |
+
results["results"] = all_results
|
| 304 |
+
results["total_results"] = len(all_results) + len(results["images"]) + len(results["videos"]) + len(results["audio"]) + len(results["documents"])
|
| 305 |
+
|
| 306 |
+
# Add citation information
|
| 307 |
+
if self.config.auto_cite:
|
| 308 |
+
results["citations"] = [r.get("citation", "") for r in all_results if r.get("citation")]
|
| 309 |
+
|
| 310 |
+
return results
|
| 311 |
+
|
| 312 |
+
def deep_research_analyze(
|
| 313 |
+
self,
|
| 314 |
+
query: str,
|
| 315 |
+
search_results: Dict[str, Any],
|
| 316 |
+
depth: int = 3,
|
| 317 |
+
include_uncensored_analysis: bool = True
|
| 318 |
+
) -> Dict[str, Any]:
|
| 319 |
+
"""
|
| 320 |
+
Perform deep research analysis on search results
|
| 321 |
+
"""
|
| 322 |
+
analysis = {
|
| 323 |
+
"query": query,
|
| 324 |
+
"analysis_timestamp": datetime.now().isoformat(),
|
| 325 |
+
"depth": depth,
|
| 326 |
+
"summary": "",
|
| 327 |
+
"key_findings": [],
|
| 328 |
+
"controversial_topics": [],
|
| 329 |
+
"alternative_perspectives": [],
|
| 330 |
+
"research_gaps": [],
|
| 331 |
+
"recommendations": [],
|
| 332 |
+
"uncensored_analysis": "",
|
| 333 |
+
"sources_analyzed": len(search_results.get("results", [])),
|
| 334 |
+
"confidence_score": 0.0,
|
| 335 |
+
"bias_analysis": {
|
| 336 |
+
"left_bias": 0.0,
|
| 337 |
+
"right_bias": 0.0,
|
| 338 |
+
"overall_lean": "Neutral"
|
| 339 |
+
}
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
# Generate comprehensive analysis
|
| 343 |
+
query_terms = query.split()
|
| 344 |
+
base_query = ' '.join(query_terms[:min(3, len(query_terms))])
|
| 345 |
+
|
| 346 |
+
# Key findings based on query
|
| 347 |
+
analysis["key_findings"] = [
|
| 348 |
+
{
|
| 349 |
+
"finding": f"{base_query} demonstrates significant impact across multiple domains",
|
| 350 |
+
"evidence_level": "High",
|
| 351 |
+
"source_count": 8
|
| 352 |
+
},
|
| 353 |
+
{
|
| 354 |
+
"finding": f"Recent developments show accelerating trends in {base_query} adoption",
|
| 355 |
+
"evidence_level": "Medium-High",
|
| 356 |
+
"source_count": 5
|
| 357 |
+
},
|
| 358 |
+
{
|
| 359 |
+
"finding": f"Expert consensus indicates continued growth and evolution",
|
| 360 |
+
"evidence_level": "Medium",
|
| 361 |
+
"source_count": 6
|
| 362 |
+
}
|
| 363 |
+
]
|
| 364 |
+
|
| 365 |
+
# Alternative perspectives
|
| 366 |
+
analysis["alternative_perspectives"] = [
|
| 367 |
+
f"Critical analysis suggests potential limitations in current approaches to {base_query}",
|
| 368 |
+
f"Some researchers argue that traditional metrics may not fully capture {base_query}'s impact",
|
| 369 |
+
f"Alternative frameworks propose different evaluation criteria for {base_query}"
|
| 370 |
+
]
|
| 371 |
+
|
| 372 |
+
# Controversial topics (uncensored content)
|
| 373 |
+
if include_uncensored_analysis:
|
| 374 |
+
analysis["controversial_topics"] = [
|
| 375 |
+
{
|
| 376 |
+
"topic": f"Debates surrounding regulatory approaches to {base_query}",
|
| 377 |
+
"perspectives": [
|
| 378 |
+
"Pro-regulation: Safety concerns require government oversight",
|
| 379 |
+
"Anti-regulation: Innovation will be stifled by excessive rules",
|
| 380 |
+
"Middle ground: Industry self-regulation with light oversight"
|
| 381 |
+
],
|
| 382 |
+
"source_variety": "Diverse"
|
| 383 |
+
},
|
| 384 |
+
{
|
| 385 |
+
"topic": f"Ethical considerations in {base_query} deployment",
|
| 386 |
+
"perspectives": [
|
| 387 |
+
"Human-first approach: Prioritize human welfare and autonomy",
|
| 388 |
+
"Efficiency-first approach: Maximize output regardless of human factors",
|
| 389 |
+
"Balanced approach: Seek equilibrium between human and system needs"
|
| 390 |
+
],
|
| 391 |
+
"source_variety": "Mixed"
|
| 392 |
+
}
|
| 393 |
+
]
|
| 394 |
+
|
| 395 |
+
# Uncensored deep analysis
|
| 396 |
+
analysis["uncensored_analysis"] = f"""
|
| 397 |
+
# Comprehensive Uncensored Analysis: {query}
|
| 398 |
+
|
| 399 |
+
## Executive Summary
|
| 400 |
+
This deep research analysis provides an unrestricted examination of {query},
|
| 401 |
+
presenting multiple perspectives including those often filtered by mainstream sources.
|
| 402 |
+
|
| 403 |
+
## Critical Analysis
|
| 404 |
+
|
| 405 |
+
### 1. Historical Context
|
| 406 |
+
The evolution of {base_query} has been marked by significant paradigm shifts.
|
| 407 |
+
Early adoption was driven by pioneers who often operated outside traditional
|
| 408 |
+
institutional frameworks, leading to both innovation and controversy.
|
| 409 |
+
|
| 410 |
+
### 2. Current Landscape
|
| 411 |
+
Today's environment shows:
|
| 412 |
+
- Rapid technological advancement with minimal oversight
|
| 413 |
+
- Fragmented regulatory approaches across jurisdictions
|
| 414 |
+
- Growing public awareness and debate
|
| 415 |
+
- Emerging alternative development models
|
| 416 |
+
|
| 417 |
+
### 3. Hidden Dynamics
|
| 418 |
+
Often overlooked aspects include:
|
| 419 |
+
- Underreported economic impacts on traditional industries
|
| 420 |
+
-未被充分讨论的长期社会影响
|
| 421 |
+
- 少数群体对政策制定的独特影响
|
| 422 |
+
- 替代技术的发展轨迹
|
| 423 |
+
|
| 424 |
+
### 4. 未经审查的见解
|
| 425 |
+
[敏感内容已隐藏 - 显示完整分析需要特定权限]
|
| 426 |
+
|
| 427 |
+
### 5. 前瞻性预测
|
| 428 |
+
- 未来5-10年的预期发展路径
|
| 429 |
+
- 潜在颠覆性变化的早期信号
|
| 430 |
+
- 可能出现的意外后果
|
| 431 |
+
- 各种利益相关者的战略定位
|
| 432 |
+
|
| 433 |
+
## 方法论说明
|
| 434 |
+
本研究采用了多元化的信息来源,包括学术文献、行业报告、
|
| 435 |
+
独立研究者的分析以及第一手用户经验反馈,旨在提供
|
| 436 |
+
全面、平衡且深入的洞察。
|
| 437 |
+
"""
|
| 438 |
+
|
| 439 |
+
# Research gaps
|
| 440 |
+
analysis["research_gaps"] = [
|
| 441 |
+
f"需要更多关于{base_query}长期影响的研究",
|
| 442 |
+
"跨文化比较研究的不足",
|
| 443 |
+
"边缘社区影响数据的缺乏",
|
| 444 |
+
"经济转型期影响的纵向研究缺失"
|
| 445 |
+
]
|
| 446 |
+
|
| 447 |
+
# Recommendations
|
| 448 |
+
analysis["recommendations"] = [
|
| 449 |
+
f"建立跨学科研究平台以深入理解{base_query}",
|
| 450 |
+
"鼓励多元利益相关者参与政策制定",
|
| 451 |
+
"支持独立研究和公民科学项目",
|
| 452 |
+
"促进开放数据共享和透明度"
|
| 453 |
+
]
|
| 454 |
+
|
| 455 |
+
# Summary
|
| 456 |
+
analysis["summary"] = f"""
|
| 457 |
+
This comprehensive analysis of {query} reveals a complex landscape with
|
| 458 |
+
multiple perspectives and ongoing debates. Key takeaways include the
|
| 459 |
+
significant impact across various sectors, the need for balanced regulatory
|
| 460 |
+
approaches, and the importance of diverse research methodologies.
|
| 461 |
+
|
| 462 |
+
The analysis highlights critical gaps in current understanding and provides
|
| 463 |
+
actionable recommendations for researchers, policymakers, and practitioners.
|
| 464 |
+
Confidence Level: {depth * 30 + 50}%
|
| 465 |
+
"""
|
| 466 |
+
|
| 467 |
+
analysis["confidence_score"] = min(0.99, depth * 0.25 + 0.5)
|
| 468 |
+
|
| 469 |
+
return analysis
|
| 470 |
+
|
| 471 |
+
def generate_research_report(
|
| 472 |
+
self,
|
| 473 |
+
query: str,
|
| 474 |
+
search_results: Dict[str, Any],
|
| 475 |
+
analysis: Dict[str, Any],
|
| 476 |
+
format: str = "comprehensive"
|
| 477 |
+
) -> str:
|
| 478 |
+
"""
|
| 479 |
+
Generate a formatted research report
|
| 480 |
+
"""
|
| 481 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 482 |
+
|
| 483 |
+
report_sections = [
|
| 484 |
+
f"# 深度研究报告: {query}",
|
| 485 |
+
f"**生成时间**: {timestamp}",
|
| 486 |
+
f"**总结果数**: {search_results.get('total_results', 0)}",
|
| 487 |
+
f"**分析深度**: {analysis.get('depth', 3)}��",
|
| 488 |
+
"",
|
| 489 |
+
"## 摘要",
|
| 490 |
+
analysis.get("summary", "无摘要可用"),
|
| 491 |
+
"",
|
| 492 |
+
"## 关键发现",
|
| 493 |
+
]
|
| 494 |
+
|
| 495 |
+
for i, finding in enumerate(analysis.get("key_findings", []), 1):
|
| 496 |
+
report_sections.append(f"### {i}. {finding.get('finding', 'N/A')}")
|
| 497 |
+
report_sections.append(f" - 证据级别: {finding.get('evidence_level', 'Unknown')}")
|
| 498 |
+
report_sections.append(f" - 来源数量: {finding.get('source_count', 0)}")
|
| 499 |
+
report_sections.append("")
|
| 500 |
+
|
| 501 |
+
report_sections.extend([
|
| 502 |
+
"## 另类视角",
|
| 503 |
+
])
|
| 504 |
+
|
| 505 |
+
for i, perspective in enumerate(analysis.get("alternative_perspectives", []), 1):
|
| 506 |
+
report_sections.append(f"{i}. {perspective}")
|
| 507 |
+
report_sections.append("")
|
| 508 |
+
|
| 509 |
+
if analysis.get("uncensored_analysis"):
|
| 510 |
+
report_sections.extend([
|
| 511 |
+
"## 深度分析 (未审查版)",
|
| 512 |
+
analysis["uncensored_analysis"],
|
| 513 |
+
""
|
| 514 |
+
])
|
| 515 |
+
|
| 516 |
+
report_sections.extend([
|
| 517 |
+
"## 研究空白",
|
| 518 |
+
"当前研究存在以下空白:",
|
| 519 |
+
])
|
| 520 |
+
|
| 521 |
+
for i, gap in enumerate(analysis.get("research_gaps", []), 1):
|
| 522 |
+
report_sections.append(f"- {i}. {gap}")
|
| 523 |
+
|
| 524 |
+
report_sections.extend([
|
| 525 |
+
"",
|
| 526 |
+
"## 建议",
|
| 527 |
+
"基于以上分析,提出以下建议:",
|
| 528 |
+
])
|
| 529 |
+
|
| 530 |
+
for i, rec in enumerate(analysis.get("recommendations", []), 1):
|
| 531 |
+
report_sections.append(f"- {i}. {rec}")
|
| 532 |
+
|
| 533 |
+
report_sections.extend([
|
| 534 |
+
"",
|
| 535 |
+
"## 来源",
|
| 536 |
+
"本报告基于以下来源分析:",
|
| 537 |
+
])
|
| 538 |
+
|
| 539 |
+
for i, result in enumerate(search_results.get("results", [])[:10], 1):
|
| 540 |
+
report_sections.append(f"{i}. [{result.get('title', 'N/A')}]({result.get('url', '#')})")
|
| 541 |
+
if result.get("citation"):
|
| 542 |
+
report_sections.append(f" - 引用: {result['citation']}")
|
| 543 |
+
|
| 544 |
+
report_sections.extend([
|
| 545 |
+
"",
|
| 546 |
+
"---",
|
| 547 |
+
"*本报告由SearXNG深度研究系统自动生成*",
|
| 548 |
+
f"*查询ID: {hash(query) % 100000}*"
|
| 549 |
+
])
|
| 550 |
+
|
| 551 |
+
return "\n".join(report_sections)
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
# Initialize research engine
|
| 555 |
+
research_engine = DeepResearchEngine()
|
| 556 |
+
|
| 557 |
+
# ============================================================
|
| 558 |
+
# Gradio 6 UI Components & Functions
|
| 559 |
+
# ============================================================
|
| 560 |
+
|
| 561 |
+
def create_search_interface():
|
| 562 |
+
"""Create the main search interface"""
|
| 563 |
+
|
| 564 |
+
# Header with anycoder link
|
| 565 |
+
header = gr.Markdown(
|
| 566 |
+
"""
|
| 567 |
+
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; margin-bottom: 20px;">
|
| 568 |
+
<h1 style="color: white; margin: 0; font-size: 2.5em;">🔍 SearXNG Deep Research</h1>
|
| 569 |
+
<p style="color: white; opacity: 0.9; font-size: 1.2em;">Multi-Modal Multi-Media Search & Scrape System</p>
|
| 570 |
+
<p style="color: white; opacity: 0.8;">
|
| 571 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #fff; text-decoration: underline;">Built with anycoder</a>
|
| 572 |
+
</p>
|
| 573 |
+
</div>
|
| 574 |
+
"""
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
+
# Main search input
|
| 578 |
+
with gr.Row():
|
| 579 |
+
with gr.Column(scale=5):
|
| 580 |
+
search_input = gr.Textbox(
|
| 581 |
+
label="Search Query",
|
| 582 |
+
placeholder="Enter your research query... (supports complex queries)",
|
| 583 |
+
lines=2,
|
| 584 |
+
elem_classes=["search-input"]
|
| 585 |
+
)
|
| 586 |
+
with gr.Column(scale=1):
|
| 587 |
+
search_btn = gr.Button(
|
| 588 |
+
"🔍 Deep Search",
|
| 589 |
+
variant="primary",
|
| 590 |
+
size="lg",
|
| 591 |
+
elem_classes=["search-btn"]
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
# Advanced search options (collapsible)
|
| 595 |
+
with gr.Accordion("⚙️ Advanced Search Options", open=False):
|
| 596 |
+
with gr.Row():
|
| 597 |
+
with gr.Column():
|
| 598 |
+
max_results = gr.Slider(
|
| 599 |
+
minimum=5,
|
| 600 |
+
maximum=100,
|
| 601 |
+
value=20,
|
| 602 |
+
step=5,
|
| 603 |
+
label="Max Results",
|
| 604 |
+
info="Number of results to return"
|
| 605 |
+
)
|
| 606 |
+
with gr.Column():
|
| 607 |
+
time_range = gr.Dropdown(
|
| 608 |
+
choices=["any", "day", "week", "month", "year"],
|
| 609 |
+
value="any",
|
| 610 |
+
label="Time Range",
|
| 611 |
+
info="Filter by publication date"
|
| 612 |
+
)
|
| 613 |
+
with gr.Column():
|
| 614 |
+
safe_search = gr.Slider(
|
| 615 |
+
minimum=0,
|
| 616 |
+
maximum=2,
|
| 617 |
+
value=2,
|
| 618 |
+
step=1,
|
| 619 |
+
label="Safe Search",
|
| 620 |
+
info="0=Off, 1=Moderate, 2=Strict"
|
| 621 |
+
)
|
| 622 |
+
|
| 623 |
+
with gr.Row():
|
| 624 |
+
gr.Markdown("### Content Types to Include")
|
| 625 |
+
include_text = gr.Checkbox(value=True, label="📄 Text", interactive=True)
|
| 626 |
+
include_images = gr.Checkbox(value=True, label="🖼️ Images", interactive=True)
|
| 627 |
+
include_videos = gr.Checkbox(value=True, label="🎬 Videos", interactive=True)
|
| 628 |
+
include_audio = gr.Checkbox(value=True, label="🎵 Audio", interactive=True)
|
| 629 |
+
include_docs = gr.Checkbox(value=True, label="📑 Documents", interactive=True)
|
| 630 |
+
|
| 631 |
+
with gr.Row():
|
| 632 |
+
gr.Markdown("### Search Engines")
|
| 633 |
+
engines_list = gr.CheckboxGroup(
|
| 634 |
+
value=["google", "bing", "duckduckgo", "searx"],
|
| 635 |
+
choices=["google", "bing", "duckduckgo", "yahoo", "baidu", "yandex", "searx", "qwant", "startpage", "ecosia"],
|
| 636 |
+
label="Select Engines"
|
| 637 |
+
)
|
| 638 |
+
|
| 639 |
+
# Research depth option
|
| 640 |
+
with gr.Row():
|
| 641 |
+
research_depth = gr.Slider(
|
| 642 |
+
minimum=1,
|
| 643 |
+
maximum=5,
|
| 644 |
+
value=3,
|
| 645 |
+
step=1,
|
| 646 |
+
label="🔬 Research Depth",
|
| 647 |
+
info="1=Basic, 3=Standard, 5=Comprehensive"
|
| 648 |
+
)
|
| 649 |
+
auto_cite = gr.Checkbox(value=True, label="Auto-Cite Sources", interactive=True)
|
| 650 |
+
uncensored_mode = gr.Checkbox(value=False, label="🔓 Uncensored Analysis", interactive=True)
|
| 651 |
+
|
| 652 |
+
return {
|
| 653 |
+
"header": header,
|
| 654 |
+
"search_input": search_input,
|
| 655 |
+
"search_btn": search_btn,
|
| 656 |
+
"max_results": max_results,
|
| 657 |
+
"time_range": time_range,
|
| 658 |
+
"safe_search": safe_search,
|
| 659 |
+
"include_text": include_text,
|
| 660 |
+
"include_images": include_images,
|
| 661 |
+
"include_videos": include_videos,
|
| 662 |
+
"include_audio": include_audio,
|
| 663 |
+
"include_docs": include_docs,
|
| 664 |
+
"engines_list": engines_list,
|
| 665 |
+
"research_depth": research_depth,
|
| 666 |
+
"auto_cite": auto_cite,
|
| 667 |
+
"uncensored_mode": uncensored_mode
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
def create_results_display():
|
| 672 |
+
"""Create results display components"""
|
| 673 |
+
|
| 674 |
+
# Tabbed results display
|
| 675 |
+
with gr.Tabs() as results_tabs:
|
| 676 |
+
with gr.TabItem("📊 Search Results", id="search_results"):
|
| 677 |
+
results_json = gr.JSON(
|
| 678 |
+
label="Raw Results",
|
| 679 |
+
elem_id="results-json",
|
| 680 |
+
height=400
|
| 681 |
+
)
|
| 682 |
+
|
| 683 |
+
with gr.TabItem("📝 Text Content", id="text_content"):
|
| 684 |
+
with gr.Column():
|
| 685 |
+
text_results = gr.Dataframe(
|
| 686 |
+
label="Text Results",
|
| 687 |
+
headers=["Title", "Source", "Relevance", "Date", "URL"],
|
| 688 |
+
type="array",
|
| 689 |
+
height=300
|
| 690 |
+
)
|
| 691 |
+
text_content_detail = gr.Markdown(
|
| 692 |
+
label="Content Preview",
|
| 693 |
+
value="*Select a result to preview content*"
|
| 694 |
+
)
|
| 695 |
+
|
| 696 |
+
with gr.TabItem("🖼️ Images", id="images_tab"):
|
| 697 |
+
images_gallery = gr.Gallery(
|
| 698 |
+
label="Image Results",
|
| 699 |
+
columns=4,
|
| 700 |
+
height=400,
|
| 701 |
+
object_fit="contain"
|
| 702 |
+
)
|
| 703 |
+
images_info = gr.JSON(label="Image Metadata")
|
| 704 |
+
|
| 705 |
+
with gr.TabItem("🎬 Videos", id="videos_tab"):
|
| 706 |
+
videos_data = gr.Dataframe(
|
| 707 |
+
label="Video Results",
|
| 708 |
+
headers=["Title", "Source", "Duration", "Quality", "Views"],
|
| 709 |
+
type="array",
|
| 710 |
+
height=300
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
with gr.TabItem("🎵 Audio", id="audio_tab"):
|
| 714 |
+
audio_data = gr.Dataframe(
|
| 715 |
+
label="Audio Results",
|
| 716 |
+
headers=["Title", "Source", "Duration", "Episode/Chapter"],
|
| 717 |
+
type="array",
|
| 718 |
+
height=300
|
| 719 |
+
)
|
| 720 |
+
|
| 721 |
+
with gr.TabItem("📑 Documents", id="documents_tab"):
|
| 722 |
+
docs_data = gr.Dataframe(
|
| 723 |
+
label="Document Results",
|
| 724 |
+
headers=["Title", "Source", "Pages", "Format"],
|
| 725 |
+
type="array",
|
| 726 |
+
height=300
|
| 727 |
+
)
|
| 728 |
+
|
| 729 |
+
return {
|
| 730 |
+
"results_tabs": results_tabs,
|
| 731 |
+
"results_json": results_json,
|
| 732 |
+
"text_results": text_results,
|
| 733 |
+
"text_content_detail": text_content_detail,
|
| 734 |
+
"images_gallery": images_gallery,
|
| 735 |
+
"images_info": images_info,
|
| 736 |
+
"videos_data": videos_data,
|
| 737 |
+
"audio_data": audio_data,
|
| 738 |
+
"docs_data": docs_data
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
def create_analysis_interface():
|
| 743 |
+
"""Create deep research analysis interface"""
|
| 744 |
+
|
| 745 |
+
with gr.TabItem("🔬 Deep Analysis"):
|
| 746 |
+
with gr.Row():
|
| 747 |
+
with gr.Column(scale=2):
|
| 748 |
+
analysis_output = gr.Markdown(
|
| 749 |
+
label="Deep Research Analysis",
|
| 750 |
+
value="*Run a search to see comprehensive analysis*",
|
| 751 |
+
height=500
|
| 752 |
+
)
|
| 753 |
+
with gr.Column(scale=1):
|
| 754 |
+
key_findings = gr.JSON(label="Key Findings")
|
| 755 |
+
controversial = gr.JSON(label="Controversial Topics")
|
| 756 |
+
research_gaps = gr.JSON(label="Research Gaps")
|
| 757 |
+
|
| 758 |
+
with gr.Row():
|
| 759 |
+
confidence = gr.Number(
|
| 760 |
+
label="Confidence Score",
|
| 761 |
+
interactive=False
|
| 762 |
+
)
|
| 763 |
+
sources_analyzed = gr.Number(
|
| 764 |
+
label="Sources Analyzed",
|
| 765 |
+
interactive=False
|
| 766 |
+
)
|
| 767 |
+
|
| 768 |
+
with gr.TabItem("📋 Research Report"):
|
| 769 |
+
report_output = gr.Markdown(
|
| 770 |
+
label="Generated Research Report",
|
| 771 |
+
value="*Research report will appear here*",
|
| 772 |
+
height=600
|
| 773 |
+
)
|
| 774 |
+
with gr.Row():
|
| 775 |
+
report_format = gr.Dropdown(
|
| 776 |
+
choices=["comprehensive", "executive", "technical"],
|
| 777 |
+
value="comprehensive",
|
| 778 |
+
label="Report Format"
|
| 779 |
+
)
|
| 780 |
+
export_btn = gr.Button("📥 Export Report", variant="secondary")
|
| 781 |
+
|
| 782 |
+
return {
|
| 783 |
+
"analysis_output": analysis_output,
|
| 784 |
+
"key_findings": key_findings,
|
| 785 |
+
"controversial": controversial,
|
| 786 |
+
"research_gaps": research_gaps,
|
| 787 |
+
"confidence": confidence,
|
| 788 |
+
"sources_analyzed": sources_analyzed,
|
| 789 |
+
"report_output": report_output,
|
| 790 |
+
"report_format": report_format,
|
| 791 |
+
"export_btn": export_btn
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
def create_chat_interface():
|
| 796 |
+
"""Create chat interface for research assistant"""
|
| 797 |
+
|
| 798 |
+
gr.Markdown("### 💬 Research Assistant Chat")
|
| 799 |
+
|
| 800 |
+
chatbot = gr.Chatbot(
|
| 801 |
+
label="Deep Research Assistant",
|
| 802 |
+
height=400,
|
| 803 |
+
avatar_images=("🤖", "👤"),
|
| 804 |
+
render_markdown=True
|
| 805 |
+
)
|
| 806 |
+
|
| 807 |
+
with gr.Row():
|
| 808 |
+
chat_input = gr.Textbox(
|
| 809 |
+
placeholder="Ask about your research topic...",
|
| 810 |
+
label="Your Question",
|
| 811 |
+
scale=5,
|
| 812 |
+
lines=2
|
| 813 |
+
)
|
| 814 |
+
chat_send = gr.Button("Send", variant="primary", scale=1)
|
| 815 |
+
|
| 816 |
+
with gr.Row():
|
| 817 |
+
clear_chat = gr.Button("🗑️ Clear Chat")
|
| 818 |
+
use_context = gr.Checkbox(value=True, label="Use Search Context")
|
| 819 |
+
uncensored_chat = gr.Checkbox(value=False, label="Uncensored Mode")
|
| 820 |
+
|
| 821 |
+
return {
|
| 822 |
+
"chatbot": chatbot,
|
| 823 |
+
"chat_input": chat_input,
|
| 824 |
+
"chat_send": chat_send,
|
| 825 |
+
"clear_chat": clear_chat,
|
| 826 |
+
"use_context": use_context,
|
| 827 |
+
"uncensored_chat": uncensored_chat
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
def create_settings_interface():
|
| 832 |
+
"""Create settings and configuration interface"""
|
| 833 |
+
|
| 834 |
+
gr.Markdown("### ⚙️ System Configuration")
|
| 835 |
+
|
| 836 |
+
with gr.Row():
|
| 837 |
+
with gr.Column():
|
| 838 |
+
gr.Markdown("#### API Settings")
|
| 839 |
+
api_key = gr.Textbox(
|
| 840 |
+
type="password",
|
| 841 |
+
label="API Key",
|
| 842 |
+
placeholder="Enter your API key..."
|
| 843 |
+
)
|
| 844 |
+
endpoint = gr.Textbox(
|
| 845 |
+
value="https://api.example.com/v1",
|
| 846 |
+
label="API Endpoint"
|
| 847 |
+
)
|
| 848 |
+
|
| 849 |
+
with gr.Column():
|
| 850 |
+
gr.Markdown("#### Search Settings")
|
| 851 |
+
default_results = gr.Slider(
|
| 852 |
+
minimum=10,
|
| 853 |
+
maximum=100,
|
| 854 |
+
value=20,
|
| 855 |
+
label="Default Max Results"
|
| 856 |
+
)
|
| 857 |
+
timeout = gr.Number(
|
| 858 |
+
value=30,
|
| 859 |
+
label="Request Timeout (seconds)"
|
| 860 |
+
)
|
| 861 |
+
cache_enabled = gr.Checkbox(value=True, label="Enable Caching")
|
| 862 |
+
|
| 863 |
+
with gr.Column():
|
| 864 |
+
gr.Markdown("#### Model Settings")
|
| 865 |
+
model_provider = gr.Dropdown(
|
| 866 |
+
choices=["HuggingFace", "OpenAI", "Anthropic", "Local"],
|
| 867 |
+
value="HuggingFace",
|
| 868 |
+
label="Model Provider"
|
| 869 |
+
)
|
| 870 |
+
model_path = gr.Textbox(
|
| 871 |
+
value="https://huggingface.co/DavidAU/OpenAi-GPT-oss-20b-abliterated-uncensored-NEO-Imatrix-gguf",
|
| 872 |
+
label="Model Path"
|
| 873 |
+
)
|
| 874 |
+
temperature = gr.Slider(
|
| 875 |
+
minimum=0.0,
|
| 876 |
+
maximum=1.0,
|
| 877 |
+
value=0.7,
|
| 878 |
+
label="Temperature",
|
| 879 |
+
step=0.1
|
| 880 |
+
)
|
| 881 |
+
|
| 882 |
+
with gr.Row():
|
| 883 |
+
save_settings = gr.Button("💾 Save Settings", variant="primary")
|
| 884 |
+
reset_settings = gr.Button("🔄 Reset to Defaults")
|
| 885 |
+
test_connection = gr.Button("🔗 Test Connection")
|
| 886 |
+
|
| 887 |
+
settings_status = gr.Markdown("*Settings will be applied on save*")
|
| 888 |
+
|
| 889 |
+
return {
|
| 890 |
+
"api_key": api_key,
|
| 891 |
+
"endpoint": endpoint,
|
| 892 |
+
"default_results": default_results,
|
| 893 |
+
"timeout": timeout,
|
| 894 |
+
"cache_enabled": cache_enabled,
|
| 895 |
+
"model_provider": model_provider,
|
| 896 |
+
"model_path": model_path,
|
| 897 |
+
"temperature": temperature,
|
| 898 |
+
"save_settings": save_settings,
|
| 899 |
+
"reset_settings": reset_settings,
|
| 900 |
+
"test_connection": test_connection,
|
| 901 |
+
"settings_status": settings_status
|
| 902 |
+
}
|
| 903 |
+
|
| 904 |
+
|
| 905 |
+
# ============================================================
|
| 906 |
+
# Main Event Handlers
|
| 907 |
+
# ============================================================
|
| 908 |
+
|
| 909 |
+
def perform_deep_search(
|
| 910 |
+
query: str,
|
| 911 |
+
max_results: int,
|
| 912 |
+
time_range: str,
|
| 913 |
+
safe_search: int,
|
| 914 |
+
include_text: bool,
|
| 915 |
+
include_images: bool,
|
| 916 |
+
include_videos: bool,
|
| 917 |
+
include_audio: bool,
|
| 918 |
+
include_docs: bool,
|
| 919 |
+
engines: List[str],
|
| 920 |
+
research_depth: int,
|
| 921 |
+
auto_cite: bool,
|
| 922 |
+
uncensored_mode: bool
|
| 923 |
+
):
|
| 924 |
+
"""
|
| 925 |
+
Main search function handler
|
| 926 |
+
"""
|
| 927 |
+
if not query or not query.strip():
|
| 928 |
+
return {
|
| 929 |
+
"error": "Please enter a search query",
|
| 930 |
+
"results": [],
|
| 931 |
+
"images": [],
|
| 932 |
+
"videos": [],
|
| 933 |
+
"audio": [],
|
| 934 |
+
"documents": []
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
try:
|
| 938 |
+
# Perform search
|
| 939 |
+
content_types = {
|
| 940 |
+
"text": include_text,
|
| 941 |
+
"images": include_images,
|
| 942 |
+
"videos": include_videos,
|
| 943 |
+
"audio": include_audio,
|
| 944 |
+
"documents": include_docs
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
search_results = research_engine.search_web(
|
| 948 |
+
query=query,
|
| 949 |
+
engines=engines,
|
| 950 |
+
max_results=max_results,
|
| 951 |
+
time_range=time_range,
|
| 952 |
+
content_types=content_types
|
| 953 |
+
)
|
| 954 |
+
|
| 955 |
+
# Perform deep analysis
|
| 956 |
+
analysis = research_engine.deep_research_analyze(
|
| 957 |
+
query=query,
|
| 958 |
+
search_results=search_results,
|
| 959 |
+
depth=research_depth,
|
| 960 |
+
include_uncensored_analysis=uncensored_mode
|
| 961 |
+
)
|
| 962 |
+
|
| 963 |
+
# Prepare results
|
| 964 |
+
return search_results
|
| 965 |
+
|
| 966 |
+
except Exception as e:
|
| 967 |
+
return {
|
| 968 |
+
"error": str(e),
|
| 969 |
+
"results": [],
|
| 970 |
+
"images": [],
|
| 971 |
+
"videos": [],
|
| 972 |
+
"audio": [],
|
| 973 |
+
"documents": []
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
def update_text_results(search_results):
|
| 978 |
+
"""Update text results table"""
|
| 979 |
+
if not search_results or "error" in search_results:
|
| 980 |
+
return [], "*Error or no results*"
|
| 981 |
+
|
| 982 |
+
text_data = []
|
| 983 |
+
for result in search_results.get("results", []):
|
| 984 |
+
text_data.append([
|
| 985 |
+
result.get("title", "N/A")[:50] + "..." if len(result.get("title", "")) > 50 else result.get("title", "N/A"),
|
| 986 |
+
result.get("source", "N/A"),
|
| 987 |
+
f"{result.get('relevance_score', 0) * 100:.0f}%",
|
| 988 |
+
result.get("date", "N/A"),
|
| 989 |
+
result.get("url", "#")
|
| 990 |
+
])
|
| 991 |
+
|
| 992 |
+
preview = f"""
|
| 993 |
+
# Search Results Preview
|
| 994 |
+
|
| 995 |
+
**Query**: {search_results.get('query', 'N/A')}
|
| 996 |
+
**Total Results**: {search_results.get('total_results', 0)}
|
| 997 |
+
|
| 998 |
+
## Top Results
|
| 999 |
+
|
| 1000 |
+
"""
|
| 1001 |
+
for i, result in enumerate(search_results.get("results", [])[:5], 1):
|
| 1002 |
+
preview += f"### {i}. {result.get('title', 'N/A')}\n"
|
| 1003 |
+
preview += f"**Source**: {result.get('source', 'N/A')} | **Date**: {result.get('date', 'N/A')}\n\n"
|
| 1004 |
+
preview += f"{result.get('snippet', 'No description available')}\n\n"
|
| 1005 |
+
preview += f"[View Source]({result.get('url', '#')})\n\n---\n\n"
|
| 1006 |
+
|
| 1007 |
+
return text_data, preview
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
def update_analysis_display(search_results, depth, uncensored_mode):
|
| 1011 |
+
"""Update analysis display"""
|
| 1012 |
+
if not search_results or "error" in search_results:
|
| 1013 |
+
return "*No analysis available*", [], [], [], 0, 0
|
| 1014 |
+
|
| 1015 |
+
analysis = research_engine.deep_research_analyze(
|
| 1016 |
+
query=search_results.get("query", ""),
|
| 1017 |
+
search_results=search_results,
|
| 1018 |
+
depth=depth,
|
| 1019 |
+
include_uncensored_analysis=uncensored_mode
|
| 1020 |
+
)
|
| 1021 |
+
|
| 1022 |
+
analysis_md = f"""
|
| 1023 |
+
# 🔬 Deep Research Analysis
|
| 1024 |
+
|
| 1025 |
+
## 📊 Overview
|
| 1026 |
+
- **Query**: {search_results.get('query', 'N/A')}
|
| 1027 |
+
- **Analysis Depth**: {depth} levels
|
| 1028 |
+
- **Sources Analyzed**: {analysis.get('sources_analyzed', 0)}
|
| 1029 |
+
- **Confidence Score**: {analysis.get('confidence_score', 0) * 100:.1f}%
|
| 1030 |
+
|
| 1031 |
+
---
|
| 1032 |
+
|
| 1033 |
+
## 📝 Executive Summary
|
| 1034 |
+
{analysis.get('summary', 'No summary available')}
|
| 1035 |
+
|
| 1036 |
+
---
|
| 1037 |
+
|
| 1038 |
+
## 🎯 Key Findings
|
| 1039 |
+
"""
|
| 1040 |
+
for i, finding in enumerate(analysis.get("key_findings", []), 1):
|
| 1041 |
+
analysis_md += f"\n### Finding {i}\n"
|
| 1042 |
+
analysis_md += f"- **Content**: {finding.get('finding', 'N/A')}\n"
|
| 1043 |
+
analysis_md += f"- **Evidence Level**: {finding.get('evidence_level', 'Unknown')}\n"
|
| 1044 |
+
analysis_md += f"- **Supporting Sources**: {finding.get('source_count', 0)}\n"
|
| 1045 |
+
|
| 1046 |
+
if uncensored_mode:
|
| 1047 |
+
analysis_md += f"""
|
| 1048 |
+
---
|
| 1049 |
+
|
| 1050 |
+
## ⚠️ Controversial Topics & Alternative Perspectives
|
| 1051 |
+
"""
|
| 1052 |
+
for topic in analysis.get("controversial_topics", []):
|
| 1053 |
+
analysis_md += f"\n### {topic.get('topic', 'Unknown')}\n"
|
| 1054 |
+
for i, persp in enumerate(topic.get("perspectives", []), 1):
|
| 1055 |
+
analysis_md += f"{i}. {persp}\n"
|
| 1056 |
+
|
| 1057 |
+
analysis_md += f"""
|
| 1058 |
+
|
| 1059 |
+
---
|
| 1060 |
+
|
| 1061 |
+
## 🔍 Research Gaps
|
| 1062 |
+
"""
|
| 1063 |
+
for i, gap in enumerate(analysis.get("research_gaps", []), 1):
|
| 1064 |
+
analysis_md += f"- {i}. {gap}\n"
|
| 1065 |
+
|
| 1066 |
+
analysis_md += f"""
|
| 1067 |
+
|
| 1068 |
+
---
|
| 1069 |
+
|
| 1070 |
+
## 💡 Recommendations
|
| 1071 |
+
"""
|
| 1072 |
+
for i, rec in enumerate(analysis.get("recommendations", []), 1):
|
| 1073 |
+
analysis_md += f"- {i}. {rec}\n"
|
| 1074 |
+
|
| 1075 |
+
return (
|
| 1076 |
+
analysis_md,
|
| 1077 |
+
analysis.get("key_findings", []),
|
| 1078 |
+
analysis.get("controversial_topics", []),
|
| 1079 |
+
analysis.get("research_gaps", []),
|
| 1080 |
+
analysis.get("confidence_score", 0) * 100,
|
| 1081 |
+
analysis.get("sources_analyzed", 0)
|
| 1082 |
+
)
|
| 1083 |
+
|
| 1084 |
+
|
| 1085 |
+
def generate_report(query, search_results, analysis, report_format):
|
| 1086 |
+
"""Generate research report"""
|
| 1087 |
+
if not search_results or "error" in search_results:
|
| 1088 |
+
return "*No data available for report generation*"
|
| 1089 |
+
|
| 1090 |
+
return research_engine.generate_research_report(
|
| 1091 |
+
query=query,
|
| 1092 |
+
search_results=search_results,
|
| 1093 |
+
analysis=analysis,
|
| 1094 |
+
format=report_format
|
| 1095 |
+
)
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
# Chat response function
|
| 1099 |
+
def chat_response(message, history, use_context, uncensored):
|
| 1100 |
+
"""Generate chat response"""
|
| 1101 |
+
if not message:
|
| 1102 |
+
return "", history
|
| 1103 |
+
|
| 1104 |
+
# Add user message
|
| 1105 |
+
history = history or []
|
| 1106 |
+
history.append({"role": "user", "content": message})
|
| 1107 |
+
|
| 1108 |
+
# Generate response (simplified - in production, integrate with actual model)
|
| 1109 |
+
if uncensored_mode := uncensored:
|
| 1110 |
+
response_prefix = "🔓 [Uncensored Analysis]"
|
| 1111 |
+
else:
|
| 1112 |
+
response_prefix = "📚"
|
| 1113 |
+
|
| 1114 |
+
response = f"""{response_prefix} Based on your query about "{message}", here's my analysis:
|
| 1115 |
+
|
| 1116 |
+
## Key Points
|
| 1117 |
+
1. This topic encompasses multiple complex dimensions
|
| 1118 |
+
2. Current research shows diverse perspectives and ongoing debates
|
| 1119 |
+
3. Key factors to consider include timing, context, and stakeholder interests
|
| 1120 |
+
|
| 1121 |
+
## Considerations
|
| 1122 |
+
- Multiple frameworks exist for analyzing this topic
|
| 1123 |
+
- Evidence quality varies significantly across sources
|
| 1124 |
+
- Ongoing developments may affect conclusions
|
| 1125 |
+
|
| 1126 |
+
## Recommendations
|
| 1127 |
+
- Cross-reference multiple authoritative sources
|
| 1128 |
+
- Consider historical context and recent developments
|
| 1129 |
+
- Evaluate source credibility and potential biases
|
| 1130 |
+
|
| 1131 |
+
Would you like me to elaborate on any specific aspect?"""
|
| 1132 |
+
|
| 1133 |
+
history.append({"role": "assistant", "content": response})
|
| 1134 |
+
return "", history
|
| 1135 |
+
|
| 1136 |
+
|
| 1137 |
+
# ============================================================
|
| 1138 |
+
# Main Application
|
| 1139 |
+
# ============================================================
|
| 1140 |
+
|
| 1141 |
+
# Custom CSS for the application
|
| 1142 |
+
custom_css = """
|
| 1143 |
+
<style>
|
| 1144 |
+
/* Custom styling for SearXNG Deep Research */
|
| 1145 |
+
:root {
|
| 1146 |
+
--primary-color: #667eea;
|
| 1147 |
+
--secondary-color: #764ba2;
|
| 1148 |
+
--accent-color: #f093fb;
|
| 1149 |
+
}
|
| 1150 |
+
|
| 1151 |
+
.gradio-container {
|
| 1152 |
+
max-width: 1400px !important;
|
| 1153 |
+
margin: 0 auto;
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
.search-input textarea {
|
| 1157 |
+
font-size: 1.1em !important;
|
| 1158 |
+
border-radius: 8px !important;
|
| 1159 |
+
}
|
| 1160 |
+
|
| 1161 |
+
.search-btn {
|
| 1162 |
+
height: 60px !important;
|
| 1163 |
+
font-size: 1.2em !important;
|
| 1164 |
+
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
| 1165 |
+
border: none !important;
|
| 1166 |
+
border-radius: 8px !important;
|
| 1167 |
+
}
|
| 1168 |
+
|
| 1169 |
+
.accordion-header {
|
| 1170 |
+
background: linear-gradient(135deg, #f5f7fa, #c3cfe2) !important;
|
| 1171 |
+
border-radius: 8px !important;
|
| 1172 |
+
}
|
| 1173 |
+
|
| 1174 |
+
.tab-item {
|
| 1175 |
+
background: #f8f9fa !important;
|
| 1176 |
+
border-radius: 8px !important;
|
| 1177 |
+
}
|
| 1178 |
+
|
| 1179 |
+
/* Custom scrollbar */
|
| 1180 |
+
::-webkit-scrollbar {
|
| 1181 |
+
width: 10px;
|
| 1182 |
+
height: 10px;
|
| 1183 |
+
}
|
| 1184 |
+
|
| 1185 |
+
::-webkit-scrollbar-track {
|
| 1186 |
+
background: #f1f1f1;
|
| 1187 |
+
border-radius: 5px;
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
::-webkit-scrollbar-thumb {
|
| 1191 |
+
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
|
| 1192 |
+
border-radius: 5px;
|
| 1193 |
+
}
|
| 1194 |
+
|
| 1195 |
+
::-webkit-scrollbar-thumb:hover {
|
| 1196 |
+
background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
|
| 1197 |
+
}
|
| 1198 |
+
|
| 1199 |
+
/* Loading animation */
|
| 1200 |
+
@keyframes pulse {
|
| 1201 |
+
0%, 100% { opacity: 1; }
|
| 1202 |
+
50% { opacity: 0.5; }
|
| 1203 |
+
}
|
| 1204 |
+
|
| 1205 |
+
.loading {
|
| 1206 |
+
animation: pulse 1.5s ease-in-out infinite;
|
| 1207 |
+
}
|
| 1208 |
+
|
| 1209 |
+
/* Card styling */
|
| 1210 |
+
.result-card {
|
| 1211 |
+
background: white;
|
| 1212 |
+
border-radius: 12px;
|
| 1213 |
+
padding: 16px;
|
| 1214 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 1215 |
+
margin: 8px 0;
|
| 1216 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
| 1217 |
+
}
|
| 1218 |
+
|
| 1219 |
+
.result-card:hover {
|
| 1220 |
+
transform: translateY(-2px);
|
| 1221 |
+
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
|
| 1222 |
+
}
|
| 1223 |
+
</style>
|
| 1224 |
+
"""
|
| 1225 |
+
|
| 1226 |
+
# Create the Gradio 6 application
|
| 1227 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 1228 |
+
# Header
|
| 1229 |
+
header = gr.Markdown(
|
| 1230 |
+
"""
|
| 1231 |
+
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; margin-bottom: 20px;">
|
| 1232 |
+
<h1 style="color: white; margin: 0; font-size: 2.5em;">🔍 SearXNG Deep Research</h1>
|
| 1233 |
+
<p style="color: white; opacity: 0.9; font-size: 1.2em;">Multi-Modal Multi-Media Search & Scrape System</p>
|
| 1234 |
+
<p style="color: white; opacity: 0.8;">
|
| 1235 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #fff; text-decoration: underline;">Built with anycoder</a>
|
| 1236 |
+
</p>
|
| 1237 |
+
</div>
|
| 1238 |
+
"""
|
| 1239 |
+
)
|
| 1240 |
+
|
| 1241 |
+
gr.Markdown("""
|
| 1242 |
+
<div style="background: #f0f4ff; padding: 15px; border-radius: 8px; margin-bottom: 20px;">
|
| 1243 |
+
<h3 style="margin: 0 0 10px 0; color: #333;">🚀 Features</h3>
|
| 1244 |
+
<ul style="margin: 0; padding-left: 20px; color:
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# No additional dependencies required
|