Streamlit facilita la creación de interfaces de usuario de investigación interactivas que los compañeros de equipo sin conocimientos técnicos pueden utilizar. Este tutorial crea una aplicación de investigación donde los usuarios escriben un tema, la aplicación ejecuta agentes de búsqueda en múltiples plataformas y muestra resultados organizados con puntuaciones de opinión y calidad de las fuentes. Cada consulta de investigación cuesta entre 0,015 y 0,025 dólares.
Requisitos previos
- Python 3.8+
- Streamlit y solicitudes instaladas
- Una clave API de Scavio de scavio.dev
- Conocimientos básicos de Streamlit
Guia paso a paso
Paso 1: Construir el backend de investigación
Cree funciones de búsqueda que llamará la aplicación Streamlit.
import os, requests, json
from datetime import datetime
API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
def research(topic, platforms=None):
"""Run multi-platform research on a topic."""
if platforms is None:
platforms = [None, 'reddit', 'youtube']
all_results = []
for platform in platforms:
body = {'query': topic, 'country_code': 'us'}
if platform:
body['platform'] = platform
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json=body).json()
for r in data.get('organic_results', [])[:5]:
all_results.append({
'title': r.get('title', ''),
'link': r.get('link', ''),
'snippet': r.get('snippet', ''),
'platform': platform or 'google',
'position': r.get('position', 0)
})
return all_results
# Test the backend
results = research('ai agent frameworks 2026')
print(f'Research returned {len(results)} results across {len(set(r["platform"] for r in results))} platforms')
for r in results[:3]:
print(f' [{r["platform"]}] {r["title"][:50]}')Paso 2: Crea la aplicación Streamlit
Cree la interfaz de usuario de investigación interactiva con entradas de búsqueda y visualización de resultados.
# streamlit_research.py
# Run with: streamlit run streamlit_research.py
# Note: This is the Streamlit app code. Testing the logic here without Streamlit.
def format_results_for_display(results):
"""Format results as the Streamlit app would display them."""
by_platform = {}
for r in results:
p = r['platform']
if p not in by_platform:
by_platform[p] = []
by_platform[p].append(r)
output = []
for platform, items in by_platform.items():
output.append(f'\n## {platform.upper()} ({len(items)} results)')
for item in items:
output.append(f' - [{item["title"][:50]}]({item["link"]})')
output.append(f' {item["snippet"][:80]}')
return '\n'.join(output)
# Simulate Streamlit workflow
topic = 'best search api for ai agents'
results = research(topic)
formatted = format_results_for_display(results)
print(f'=== Research Results: "{topic}" ===')
print(formatted)
print(f'\nCost: ${len(set(r["platform"] for r in results)) * 0.005:.3f}')Paso 3: Agregar puntuación de calidad de fuente
Califique los resultados por autoridad de dominio y actualidad para mejorar la calidad de la investigación.
TRUSTED_DOMAINS = ['github.com', 'stackoverflow.com', 'docs.python.org', 'arxiv.org',
'developer.mozilla.org', 'aws.amazon.com', 'cloud.google.com']
FORUM_DOMAINS = ['reddit.com', 'news.ycombinator.com', 'dev.to']
def score_source(result):
link = result.get('link', '')
score = 50 # base score
for d in TRUSTED_DOMAINS:
if d in link:
score += 30
break
for d in FORUM_DOMAINS:
if d in link:
score += 10
break
if '2026' in result.get('title', '') or '2026' in result.get('snippet', ''):
score += 15
if result.get('position', 99) <= 3:
score += 10
return min(score, 100)
def research_with_scores(topic):
results = research(topic)
for r in results:
r['quality_score'] = score_source(r)
results.sort(key=lambda x: x['quality_score'], reverse=True)
print(f'\n=== Scored Research: "{topic}" ===')
for r in results[:8]:
print(f' [{r["quality_score"]:3}] [{r["platform"]:7}] {r["title"][:45]}')
avg = sum(r['quality_score'] for r in results) / len(results) if results else 0
print(f'\n Avg quality: {avg:.0f}/100 | Sources: {len(results)}')
research_with_scores('python web framework comparison 2026')Ejemplo en Python
import os, requests
SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}
def quick_research(topic):
for platform in [None, 'reddit']:
body = {'query': topic, 'country_code': 'us'}
if platform: body['platform'] = platform
data = requests.post('https://api.scavio.dev/api/v1/search', headers=SH, json=body).json()
label = platform or 'google'
print(f'[{label}] {len(data.get("organic_results", []))} results')
quick_research('ai agent frameworks 2026')
print('Cost: $0.010')Ejemplo en JavaScript
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
async function research(topic) {
for (const p of [null, 'reddit']) {
const body = { query: topic, country_code: 'us', ...(p && { platform: p }) };
const data = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: SH, body: JSON.stringify(body)
}).then(r => r.json());
console.log(`[${p || 'google'}] ${(data.organic_results || []).length} results`);
}
}
await research('ai agent frameworks 2026');Salida esperada
Research returned 15 results across 3 platforms
[google] Top AI Agent Frameworks 2026: Complete Guide
[google] LangChain vs CrewAI vs Autogen Comparison
[reddit] Best framework for building AI agents?
=== Scored Research: "python web framework comparison 2026" ===
[ 90] [google ] Python Web Frameworks 2026 - Real Python
[ 80] [google ] FastAPI vs Django vs Flask Performance 2026
[ 75] [reddit ] What framework are you using in 2026?
[ 65] [youtube] Python Framework Comparison Tutorial
Avg quality: 68/100 | Sources: 15