Spaces:
Build error
Build error
parth parekh commited on
Commit ·
e43c18e
1
Parent(s): 008262f
added more workers
Browse files- Dockerfile +1 -1
- test.py +17 -6
Dockerfile
CHANGED
|
@@ -25,4 +25,4 @@ RUN chown -R user:user /app
|
|
| 25 |
# Switch to the new user
|
| 26 |
USER user
|
| 27 |
|
| 28 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 25 |
# Switch to the new user
|
| 26 |
USER user
|
| 27 |
|
| 28 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "4"]
|
test.py
CHANGED
|
@@ -103,16 +103,20 @@ test_texts = [
|
|
| 103 |
"For my number, follow the clues hidden in Da Vinci's most famous painting."
|
| 104 |
|
| 105 |
]
|
|
|
|
| 106 |
|
| 107 |
url = "https://vidhitmakvana1-contact-sharing-recognizer-api.hf.space/detect_contact"
|
| 108 |
|
| 109 |
async def process_text(session, text):
|
| 110 |
payload = {"text": text}
|
| 111 |
headers = {"Content-Type": "application/json"}
|
| 112 |
-
|
|
|
|
| 113 |
async with session.post(url, data=json.dumps(payload), headers=headers) as response:
|
| 114 |
if response.status == 200:
|
| 115 |
result = await response.json()
|
|
|
|
|
|
|
| 116 |
return result
|
| 117 |
else:
|
| 118 |
print(f"Error for text: {text}")
|
|
@@ -124,23 +128,30 @@ async def main():
|
|
| 124 |
async with aiohttp.ClientSession() as session:
|
| 125 |
tasks = [process_text(session, text) for text in test_texts]
|
| 126 |
results = await tqdm.gather(*tasks)
|
| 127 |
-
|
| 128 |
correct_predictions = 0
|
| 129 |
total_predictions = len(results)
|
| 130 |
-
|
|
|
|
| 131 |
for text, result in zip(test_texts, results):
|
| 132 |
if result:
|
| 133 |
print(f"Text: {result['text']}")
|
| 134 |
print(f"Contact Probability: {result['contact_probability']:.4f}")
|
| 135 |
print(f"Is Contact Info: {result['is_contact_info']}")
|
|
|
|
| 136 |
print("---")
|
| 137 |
-
|
| 138 |
# Assuming all texts in test_texts are actually contact information
|
| 139 |
if result['is_contact_info']:
|
| 140 |
correct_predictions += 1
|
| 141 |
-
|
|
|
|
|
|
|
| 142 |
accuracy = correct_predictions / total_predictions
|
|
|
|
| 143 |
print(f"Accuracy: {accuracy:.2f}")
|
|
|
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
| 146 |
-
|
|
|
|
|
|
| 103 |
"For my number, follow the clues hidden in Da Vinci's most famous painting."
|
| 104 |
|
| 105 |
]
|
| 106 |
+
import time
|
| 107 |
|
| 108 |
url = "https://vidhitmakvana1-contact-sharing-recognizer-api.hf.space/detect_contact"
|
| 109 |
|
| 110 |
async def process_text(session, text):
|
| 111 |
payload = {"text": text}
|
| 112 |
headers = {"Content-Type": "application/json"}
|
| 113 |
+
|
| 114 |
+
start_time = time.time()
|
| 115 |
async with session.post(url, data=json.dumps(payload), headers=headers) as response:
|
| 116 |
if response.status == 200:
|
| 117 |
result = await response.json()
|
| 118 |
+
end_time = time.time()
|
| 119 |
+
result['response_time'] = end_time - start_time
|
| 120 |
return result
|
| 121 |
else:
|
| 122 |
print(f"Error for text: {text}")
|
|
|
|
| 128 |
async with aiohttp.ClientSession() as session:
|
| 129 |
tasks = [process_text(session, text) for text in test_texts]
|
| 130 |
results = await tqdm.gather(*tasks)
|
| 131 |
+
|
| 132 |
correct_predictions = 0
|
| 133 |
total_predictions = len(results)
|
| 134 |
+
total_response_time = 0
|
| 135 |
+
|
| 136 |
for text, result in zip(test_texts, results):
|
| 137 |
if result:
|
| 138 |
print(f"Text: {result['text']}")
|
| 139 |
print(f"Contact Probability: {result['contact_probability']:.4f}")
|
| 140 |
print(f"Is Contact Info: {result['is_contact_info']}")
|
| 141 |
+
print(f"Response Time: {result['response_time']:.4f} seconds")
|
| 142 |
print("---")
|
| 143 |
+
|
| 144 |
# Assuming all texts in test_texts are actually contact information
|
| 145 |
if result['is_contact_info']:
|
| 146 |
correct_predictions += 1
|
| 147 |
+
|
| 148 |
+
total_response_time += result['response_time']
|
| 149 |
+
|
| 150 |
accuracy = correct_predictions / total_predictions
|
| 151 |
+
average_response_time = total_response_time / total_predictions
|
| 152 |
print(f"Accuracy: {accuracy:.2f}")
|
| 153 |
+
print(f"Average Response Time: {average_response_time:.4f} seconds")
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
| 156 |
+
while True:
|
| 157 |
+
asyncio.run(main())
|