satishsnv commited on
Commit
20929ce
Β·
1 Parent(s): 01a84b4

updated readme

Browse files
Files changed (3) hide show
  1. README.md +43 -15
  2. README_HF.md +1 -0
  3. test.py +13 -2
README.md CHANGED
@@ -1,3 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
1
  # Address Detection and Summarization API
2
 
3
  A FastAPI application that provides two main endpoints for address detection and text summarization with sentiment analysis using OpenAI's GPT models.
@@ -6,7 +17,7 @@ A FastAPI application that provides two main endpoints for address detection and
6
 
7
  - **Address Detection**: Extracts addresses from text content
8
  - **Text Summarization**: Generates summaries with sentiment analysis
9
- - **OpenAI Integration**: Uses GPT-3.5-turbo for natural language processing
10
  - **Header-based Authentication**: OpenAI API key passed via `x-api-key` header
11
  - **RESTful API**: Clean and simple API endpoints
12
 
@@ -37,22 +48,22 @@ A FastAPI application that provides two main endpoints for address detection and
37
  Start the FastAPI server:
38
 
39
  ```bash
40
- python main.py
41
  ```
42
 
43
  Or using uvicorn directly:
44
 
45
  ```bash
46
- uvicorn main:app --host 0.0.0.0 --port 8500 --reload
47
  ```
48
 
49
- The API will be available at: http://localhost:8500
50
 
51
  ## API Documentation
52
 
53
  Once running, visit:
54
- - Interactive API docs: http://localhost:8500/docs
55
- - ReDoc documentation: http://localhost:8500/redoc
56
 
57
  ## API Endpoints
58
 
@@ -89,7 +100,7 @@ x-api-key: your_openai_api_key_here
89
 
90
  **Example:**
91
  ```bash
92
- curl -X POST "http://localhost:8500/address-detection" \
93
  -H "Content-Type: application/json" \
94
  -H "x-api-key: your_openai_api_key_here" \
95
  -d '{
@@ -134,7 +145,7 @@ x-api-key: your_openai_api_key_here
134
 
135
  **Example:**
136
  ```bash
137
- curl -X POST "http://localhost:8500/summarize" \
138
  -H "Content-Type: application/json" \
139
  -H "x-api-key: your_openai_api_key_here" \
140
  -d '{
@@ -143,6 +154,22 @@ curl -X POST "http://localhost:8500/summarize" \
143
  }'
144
  ```
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  ## Testing
147
 
148
  Before running tests, make sure to set your OpenAI API key as an environment variable:
@@ -154,7 +181,7 @@ export OPENAI_API_KEY="your_openai_api_key_here"
154
  Then run the test script to verify the endpoints:
155
 
156
  ```bash
157
- python test_api.py
158
  ```
159
 
160
  Make sure the server is running before executing the tests.
@@ -165,12 +192,13 @@ The test script will also test error handling by making requests without the API
165
 
166
  ```
167
  dummy_add-det_summ_ser/
168
- β”œβ”€β”€ main.py # Main FastAPI application
169
- β”œβ”€β”€ test_api.py # Test script for API endpoints
170
  β”œβ”€β”€ requirements.txt # Python dependencies
171
- β”œβ”€β”€ .env.example # Environment variables template
172
- β”œβ”€β”€ .venv/ # Virtual environment
173
- └── README.md # This file
 
174
  ```
175
 
176
  ## Dependencies
@@ -196,7 +224,7 @@ All errors return appropriate HTTP status codes and descriptive error messages.
196
  ## Notes
197
 
198
  - **API Key Security**: The OpenAI API key must be passed in the `x-api-key` header for each request
199
- - The API uses GPT-3.5-turbo model by default
200
  - Sentiment scores range from -1.0 (most negative) to 1.0 (most positive)
201
  - Address detection returns addresses concatenated with ' || ' separator
202
  - The `entity_urn` field is used instead of `entity_id` for better naming convention
 
1
+ ---
2
+ title: Address Detection and Summarization API
3
+ emoji: πŸ πŸ“
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ sdk_version: "4.40.0"
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
  # Address Detection and Summarization API
13
 
14
  A FastAPI application that provides two main endpoints for address detection and text summarization with sentiment analysis using OpenAI's GPT models.
 
17
 
18
  - **Address Detection**: Extracts addresses from text content
19
  - **Text Summarization**: Generates summaries with sentiment analysis
20
+ - **OpenAI Integration**: Uses GPT-4 for natural language processing
21
  - **Header-based Authentication**: OpenAI API key passed via `x-api-key` header
22
  - **RESTful API**: Clean and simple API endpoints
23
 
 
48
  Start the FastAPI server:
49
 
50
  ```bash
51
+ python app.py
52
  ```
53
 
54
  Or using uvicorn directly:
55
 
56
  ```bash
57
+ uvicorn app:app --host 0.0.0.0 --port 7860 --reload
58
  ```
59
 
60
+ The API will be available at: http://localhost:7860 (or http://localhost:8500 for local development)
61
 
62
  ## API Documentation
63
 
64
  Once running, visit:
65
+ - Interactive API docs: http://localhost:7860/docs (or :8500 for local)
66
+ - ReDoc documentation: http://localhost:7860/redoc
67
 
68
  ## API Endpoints
69
 
 
100
 
101
  **Example:**
102
  ```bash
103
+ curl -X POST "http://localhost:7860/address-detection" \
104
  -H "Content-Type: application/json" \
105
  -H "x-api-key: your_openai_api_key_here" \
106
  -d '{
 
145
 
146
  **Example:**
147
  ```bash
148
+ curl -X POST "http://localhost:7860/summarize" \
149
  -H "Content-Type: application/json" \
150
  -H "x-api-key: your_openai_api_key_here" \
151
  -d '{
 
154
  }'
155
  ```
156
 
157
+ ## Deployment
158
+
159
+ This API is designed for easy deployment to Hugging Face Spaces using Docker.
160
+
161
+ ### For Hugging Face Spaces:
162
+ 1. Upload: `app.py`, `Dockerfile`, `requirements.txt`, `README.md`
163
+ 2. The service will automatically run on port 7860
164
+ 3. API will be available at: `https://your-space-name.hf.space`
165
+
166
+ ### For Local Development:
167
+ ```bash
168
+ python app.py # Runs on port 8500
169
+ ```
170
+
171
+ See `DEPLOY.md` for detailed deployment instructions.
172
+
173
  ## Testing
174
 
175
  Before running tests, make sure to set your OpenAI API key as an environment variable:
 
181
  Then run the test script to verify the endpoints:
182
 
183
  ```bash
184
+ python test.py
185
  ```
186
 
187
  Make sure the server is running before executing the tests.
 
192
 
193
  ```
194
  dummy_add-det_summ_ser/
195
+ β”œβ”€β”€ app.py # Main FastAPI application
196
+ β”œβ”€β”€ test.py # Test script for API endpoints
197
  β”œβ”€β”€ requirements.txt # Python dependencies
198
+ β”œβ”€β”€ Dockerfile # Docker configuration for deployment
199
+ β”œβ”€β”€ README.md # This file
200
+ β”œβ”€β”€ DEPLOY.md # Deployment instructions
201
+ └── .gitignore # Git ignore patterns
202
  ```
203
 
204
  ## Dependencies
 
224
  ## Notes
225
 
226
  - **API Key Security**: The OpenAI API key must be passed in the `x-api-key` header for each request
227
+ - The API uses GPT-4o model by default
228
  - Sentiment scores range from -1.0 (most negative) to 1.0 (most positive)
229
  - Address detection returns addresses concatenated with ' || ' separator
230
  - The `entity_urn` field is used instead of `entity_id` for better naming convention
README_HF.md CHANGED
@@ -4,6 +4,7 @@ emoji: πŸ πŸ“
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: docker
 
7
  pinned: false
8
  license: mit
9
  ---
 
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  license: mit
10
  ---
test.py CHANGED
@@ -1,19 +1,27 @@
1
  #!/usr/bin/env python3
2
  """
3
  Simple test script for the deployed API
4
- Update BASE_URL to your Hugging Face Space URL
5
  """
6
 
7
  import httpx
8
  import json
9
  import os
 
10
 
11
- # Update this to your actual Hugging Face Space URL
12
  BASE_URL = "https://your-space-name.hf.space"
 
13
 
14
  def test_api():
15
  """Test the deployed API"""
16
 
 
 
 
 
 
 
17
  # Get OpenAI API key from environment
18
  api_key = os.getenv("OPENAI_API_KEY")
19
  if not api_key:
@@ -68,6 +76,9 @@ def test_api():
68
  print(f"❌ Summarization failed: {e}")
69
 
70
  print(f"\nπŸ“– View docs at: {BASE_URL}/docs")
 
 
 
71
 
72
  if __name__ == "__main__":
73
  test_api()
 
1
  #!/usr/bin/env python3
2
  """
3
  Simple test script for the deployed API
4
+ Update BASE_URL to your Hugging Face Space URL or local server
5
  """
6
 
7
  import httpx
8
  import json
9
  import os
10
+ import sys
11
 
12
+ # Update this to your actual Hugging Face Space URL or use "local" for localhost:7860
13
  BASE_URL = "https://your-space-name.hf.space"
14
+ # BASE_URL = "http://localhost:7860" # Uncomment for local testing
15
 
16
  def test_api():
17
  """Test the deployed API"""
18
 
19
+ # Handle local testing
20
+ if len(sys.argv) > 1 and sys.argv[1] == "local":
21
+ global BASE_URL
22
+ BASE_URL = "http://localhost:7860"
23
+ print("🏠 Testing local server...")
24
+
25
  # Get OpenAI API key from environment
26
  api_key = os.getenv("OPENAI_API_KEY")
27
  if not api_key:
 
76
  print(f"❌ Summarization failed: {e}")
77
 
78
  print(f"\nπŸ“– View docs at: {BASE_URL}/docs")
79
+ print(f"\nπŸ’‘ Usage:")
80
+ print(f" python test.py # Test Hugging Face deployment")
81
+ print(f" python test.py local # Test local server")
82
 
83
  if __name__ == "__main__":
84
  test_api()