satishsnv commited on
Commit
61c663e
Β·
1 Parent(s): 20929ce

deleted main.py

Browse files
Files changed (2) hide show
  1. main.py +0 -0
  2. test.py +65 -10
main.py DELETED
File without changes
test.py CHANGED
@@ -8,9 +8,15 @@ 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():
@@ -21,6 +27,13 @@ def test_api():
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")
@@ -37,41 +50,74 @@ def test_api():
37
  print(f"πŸ§ͺ Testing API at: {BASE_URL}")
38
  print("=" * 50)
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Test health endpoint
41
  try:
42
- with httpx.Client(timeout=30.0) as client:
43
  response = client.get(f"{BASE_URL}/health")
44
  print(f"βœ… Health Check: {response.status_code}")
45
- print(f" {response.json()}")
 
 
 
 
 
 
46
  except Exception as e:
47
  print(f"❌ Health check failed: {e}")
48
 
49
  # Test address detection
50
  try:
51
- with httpx.Client(timeout=30.0) as client:
52
  data = {
53
  "entity_urn": "test_001",
54
  "content": "Send package to 123 Main Street, New York, NY 10001"
55
  }
56
  response = client.post(f"{BASE_URL}/address-detection", json=data, headers=headers)
57
  print(f"βœ… Address Detection: {response.status_code}")
58
- result = response.json()
59
- print(f" Addresses: {result.get('result', 'N/A')}")
 
 
 
 
 
 
60
  except Exception as e:
61
  print(f"❌ Address detection failed: {e}")
62
 
63
  # Test summarization
64
  try:
65
- with httpx.Client(timeout=30.0) as client:
66
  data = {
67
  "entity_urn": "test_002",
68
  "content": "I love this product! It's amazing and exceeded my expectations."
69
  }
70
  response = client.post(f"{BASE_URL}/summarize", json=data, headers=headers)
71
  print(f"βœ… Summarization: {response.status_code}")
72
- result = response.json()
73
- print(f" Summary: {result.get('result', 'N/A')}")
74
- print(f" Sentiment: {result.get('sentiment', 'N/A')}")
 
 
 
 
 
 
75
  except Exception as e:
76
  print(f"❌ Summarization failed: {e}")
77
 
@@ -79,6 +125,15 @@ def test_api():
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()
 
8
  import json
9
  import os
10
  import sys
11
+ from dotenv import load_dotenv
12
+
13
+ load_dotenv() # Load environment variables from .env file
14
+
15
+ # Possible Hugging Face Space URLs to try
16
+
17
 
18
  # Update this to your actual Hugging Face Space URL or use "local" for localhost:7860
19
+ BASE_URL = "https://snvskiit/content_processor.hf.space" # Default to first URL
20
  # BASE_URL = "http://localhost:7860" # Uncomment for local testing
21
 
22
  def test_api():
 
27
  global BASE_URL
28
  BASE_URL = "http://localhost:7860"
29
  print("🏠 Testing local server...")
30
+ else:
31
+ print("🌐 Testing Hugging Face Space deployment...")
32
+ print("πŸ” If 404 errors occur, the Space might be:")
33
+ print(" β€’ Not properly deployed")
34
+ print(" β€’ Sleeping (try refreshing the Space URL in browser)")
35
+ print(" β€’ Using a different URL")
36
+ print(" β€’ Having deployment issues")
37
 
38
  # Get OpenAI API key from environment
39
  api_key = os.getenv("OPENAI_API_KEY")
 
50
  print(f"πŸ§ͺ Testing API at: {BASE_URL}")
51
  print("=" * 50)
52
 
53
+ # Test root endpoint first
54
+ try:
55
+ with httpx.Client(timeout=30.0, verify=False) as client:
56
+ response = client.get(f"{BASE_URL}/")
57
+ print(f"βœ… Root Endpoint: {response.status_code}")
58
+ if response.status_code == 200:
59
+ try:
60
+ print(f" {response.json()}")
61
+ except:
62
+ print(f" Response: {response.text[:200]}...")
63
+ else:
64
+ print(f" Error response: {response.text[:200]}...")
65
+ except Exception as e:
66
+ print(f"❌ Root endpoint failed: {e}")
67
+
68
  # Test health endpoint
69
  try:
70
+ with httpx.Client(timeout=30.0, verify=False) as client:
71
  response = client.get(f"{BASE_URL}/health")
72
  print(f"βœ… Health Check: {response.status_code}")
73
+ if response.status_code == 200:
74
+ try:
75
+ print(f" {response.json()}")
76
+ except:
77
+ print(f" Response: {response.text[:200]}...")
78
+ else:
79
+ print(f" Error response: {response.text[:200]}...")
80
  except Exception as e:
81
  print(f"❌ Health check failed: {e}")
82
 
83
  # Test address detection
84
  try:
85
+ with httpx.Client(timeout=30.0, verify=False) as client:
86
  data = {
87
  "entity_urn": "test_001",
88
  "content": "Send package to 123 Main Street, New York, NY 10001"
89
  }
90
  response = client.post(f"{BASE_URL}/address-detection", json=data, headers=headers)
91
  print(f"βœ… Address Detection: {response.status_code}")
92
+ if response.status_code == 200:
93
+ try:
94
+ result = response.json()
95
+ print(f" Addresses: {result.get('result', 'N/A')}")
96
+ except:
97
+ print(f" Response: {response.text[:200]}...")
98
+ else:
99
+ print(f" Error response: {response.text[:200]}...")
100
  except Exception as e:
101
  print(f"❌ Address detection failed: {e}")
102
 
103
  # Test summarization
104
  try:
105
+ with httpx.Client(timeout=30.0, verify=False) as client:
106
  data = {
107
  "entity_urn": "test_002",
108
  "content": "I love this product! It's amazing and exceeded my expectations."
109
  }
110
  response = client.post(f"{BASE_URL}/summarize", json=data, headers=headers)
111
  print(f"βœ… Summarization: {response.status_code}")
112
+ if response.status_code == 200:
113
+ try:
114
+ result = response.json()
115
+ print(f" Summary: {result.get('result', 'N/A')}")
116
+ print(f" Sentiment: {result.get('sentiment', 'N/A')}")
117
+ except:
118
+ print(f" Response: {response.text[:200]}...")
119
+ else:
120
+ print(f" Error response: {response.text[:200]}...")
121
  except Exception as e:
122
  print(f"❌ Summarization failed: {e}")
123
 
 
125
  print(f"\nπŸ’‘ Usage:")
126
  print(f" python test.py # Test Hugging Face deployment")
127
  print(f" python test.py local # Test local server")
128
+
129
+ if "hf.space" in BASE_URL:
130
+ print(f"\nπŸ”§ Troubleshooting Hugging Face Space:")
131
+ print(f" β€’ Check if Space is active: {BASE_URL}")
132
+ print(f" β€’ Try refreshing the Space in browser to wake it up")
133
+ print(f" β€’ Check Space logs for deployment errors")
134
+ print(f" β€’ Verify the Space URL is correct")
135
+ print(f" β€’ Try alternative URLs:")
136
+
137
 
138
  if __name__ == "__main__":
139
  test_api()