# Data Processing

> Process and analyze data with AI.

**URL:** https://inference.sh/docs/examples/data-processing
**Last updated:** 2026-09-18

---

Process and analyze data with AI.

---

## Text Summarization

Condense long documents:

```python
from inferencesh import inference

client = inference(api_key="inf_your_key")

result = client.run({
    "app": "infsh/summarize",
    "input": {
        "text": long_document,
        "max_length": 200
    }
})

print(result["output"]["summary"])
```

---

## Document Analysis

Extract information from documents:

```python
result = client.run({
    "app": "infsh/document-qa",
    "input": {
        "document": "/path/to/contract.pdf",
        "questions": [
            "What is the contract duration?",
            "What are the payment terms?",
            "Who are the parties involved?"
        ]
    }
})

for answer in result["output"]["answers"]:
    print(f"Q: {answer['question']}")
    print(f"A: {answer['answer']}\n")
```

---

## Sentiment Analysis

Analyze text sentiment:

```python
result = client.run({
    "app": "infsh/sentiment",
    "input": {
        "texts": [
            "This product is amazing!",
            "Terrible customer service.",
            "It's okay, nothing special."
        ]
    }
})

for item in result["output"]["results"]:
    print(f"{item['text'][:30]}... → {item['sentiment']} ({item['score']:.2f})")
```

Output:
```
This product is amazing!... → positive (0.95)
Terrible customer service.... → negative (0.89)
It's okay, nothing special.... → neutral (0.67)
```

---

## Batch Processing

Process many items efficiently:

```python
# Process 100 texts
texts = [...]  # Your data

# Run in batches
batch_size = 10
results = []

for i in range(0, len(texts), batch_size):
    batch = texts[i:i + batch_size]
    
    result = client.run({
        "app": "infsh/summarize",
        "input": {"texts": batch}
    })
    
    results.extend(result["output"]["summaries"])
```

---

## With Agent

Create a data analysis agent:

```
You: Analyze this CSV file and tell me the key insights

Agent: I'll analyze your data.
       [Loading CSV...]
       [Running analysis...]
       
       Key insights from your sales data:
       
       📊 Overview:
       - Total records: 15,432
       - Date range: Jan 2023 - Dec 2024
       - Total revenue: $2.4M
       
       📈 Trends:
       - Q4 shows 23% higher sales than Q1
       - Product A is top performer (34% of revenue)
       - Customer retention rate: 67%
       
       ⚠️ Anomalies:
       - March 2024 shows unusual spike (investigate)
       - Category C declining (-15% YoY)
       
       Would you like me to create visualizations?
```

---

## Common Data Apps

| App | Use Case |
|-----|----------|
| `summarize` | Condense long text |
| `sentiment` | Analyze tone/sentiment |
| `document-qa` | Q&A over documents |
| `extract` | Extract structured data |
| `translate` | Language translation |
| `classify` | Categorize text |

---

## Tips

**For large datasets:**
- Use batch processing
- Consider streaming for real-time results
- Run on private workers for data privacy

**For accuracy:**
- Clean your data first
- Be specific in prompts
- Validate results on a sample

---

## Next

→ [Multi-Agent System](/docs/examples/multi-agent)
