File size: 2,898 Bytes
01a84b4
 
 
 
 
 
20929ce
01a84b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Address Detection and Summarization API
emoji: πŸ πŸ“
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
license: mit
---

# Address Detection and Summarization API

A FastAPI service that provides two main endpoints for AI-powered text processing:

## πŸš€ Features

- 🏠 **Address Detection**: Extracts and formats addresses from unstructured text
- πŸ“ **Text Summarization**: Creates concise summaries with sentiment analysis
- πŸ€– **OpenAI Integration**: Uses GPT-4 for natural language processing
- πŸ” **Secure**: API key required via `x-api-key` header
- πŸ“Š **Sentiment Analysis**: Returns sentiment label and score (-1.0 to 1.0)

## πŸ“‹ API Endpoints

### Root & Health
- `GET /` - API information
- `GET /health` - Health check
- `GET /docs` - Interactive API documentation

### Address Detection
`POST /address-detection`

Extract addresses from text content.

**Request:**
```json
{
  "entity_urn": "unique_id",
  "content": "Please send to 123 Main Street, New York, NY 10001"
}
```

**Headers:**
```
Content-Type: application/json
x-api-key: your_openai_api_key
```

### Text Summarization  
`POST /summarize`

Generate summary with sentiment analysis.

**Request:**
```json
{
  "entity_urn": "unique_id",
  "content": "Your text content to summarize..."
}
```

## πŸ”§ Usage Examples

### Using curl:

```bash
# Address Detection
curl -X POST "https://your-space-name.hf.space/address-detection" \
     -H "Content-Type: application/json" \
     -H "x-api-key: your_openai_api_key" \
     -d '{"entity_urn": "test", "content": "Send to 123 Main St, NYC"}'

# Summarization
curl -X POST "https://your-space-name.hf.space/summarize" \
     -H "Content-Type: application/json" \
     -H "x-api-key: your_openai_api_key" \
     -d '{"entity_urn": "test", "content": "I love this product!"}'
```

### Response Format:

```json
{
  "message": "success",
  "result": "extracted_addresses || separated",
  "action_type": "detect_address",
  "entity_urn": "test",
  "sentiment": null
}
```

For summarization, `sentiment` contains:
```json
{
  "label": "positive",
  "score": 0.8
}
```

## πŸ”‘ Authentication

You need an OpenAI API key to use this service:

1. Get your API key from [OpenAI Platform](https://platform.openai.com/)
2. Include it in the `x-api-key` header with each request
3. No registration required - just use your own key

## πŸ—οΈ Built With

- **FastAPI** 0.115.14 - Modern web framework
- **OpenAI** 1.92.1 - AI language models  
- **Pydantic** 2.11.7 - Data validation
- **Python** 3.12 - Runtime

## πŸ“– Documentation

Visit `/docs` for interactive API documentation with request/response examples and testing interface.

## πŸ”’ Security & Privacy

- Your OpenAI API key is required for each request
- No API keys are stored on our servers
- All requests are processed in real-time
- No conversation history is retained