parth parekh
commited on
Commit
·
3c4c0f5
1
Parent(s):
05af594
removed gargabe roberta
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import torch
|
4 |
-
from transformers import
|
5 |
from torch.nn.functional import softmax
|
6 |
|
7 |
app = FastAPI(
|
@@ -14,8 +14,8 @@ app = FastAPI(
|
|
14 |
class ContactDetector:
|
15 |
def __init__(self):
|
16 |
cache_dir = "/app/model_cache"
|
17 |
-
self.tokenizer =
|
18 |
-
self.model =
|
19 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
20 |
self.model.to(self.device)
|
21 |
self.model.eval()
|
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import torch
|
4 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
5 |
from torch.nn.functional import softmax
|
6 |
|
7 |
app = FastAPI(
|
|
|
14 |
class ContactDetector:
|
15 |
def __init__(self):
|
16 |
cache_dir = "/app/model_cache"
|
17 |
+
self.tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', cache_dir=cache_dir)
|
18 |
+
self.model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2, cache_dir=cache_dir)
|
19 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
20 |
self.model.to(self.device)
|
21 |
self.model.eval()
|
test.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
test_texts = [
|
5 |
+
"My email is [email protected]",
|
6 |
+
"Call me at (123) 456-7890",
|
7 |
+
"I live at 123 Main St, New York, NY 10001",
|
8 |
+
"Let's meet at the park tomorrow",
|
9 |
+
"My phone number is 555-1234",
|
10 |
+
"You can reach me on Skype: user123",
|
11 |
+
"Reach me at one two three dot four five six dot seven eight nine zero",
|
12 |
+
"My handle is at_symbol_user_123 on that bird app",
|
13 |
+
"Drop me a line: first_name (dot) last_name [at] big_search_engine (dot) com",
|
14 |
+
"Ring me: area code seven-seven-seven then half a dozen, a quartet, and two pairs",
|
15 |
+
"Find me on the gram: @cool_user_2023",
|
16 |
+
"I'm on that professional network, just search for John Doe from Acme Corp",
|
17 |
+
"Send a raven to Winterfell, care of the Stark family",
|
18 |
+
"Ping me on IRC: /msg CoolDude42",
|
19 |
+
"You can find me at one two three Fake Street, Anytown, State of Confusion",
|
20 |
+
"My digits are the first ten prime numbers in order",
|
21 |
+
"Contact info: tango alpha november golf oscar at yankee alpha hotel oscar oscar dot charlie oscar mike",
|
22 |
+
"Beep me at 555 (not a real area code) then 867-5309",
|
23 |
+
"I'm on that app where messages disappear, username: GhostWriter99",
|
24 |
+
"Reach out via electronic mail to 'surname underscore initial' at that fruit company dot com",
|
25 |
+
"Call me maybe? Area code is square root of 169, then 555-CHAT",
|
26 |
+
]
|
27 |
+
|
28 |
+
url = "https://vidhitmakvana1-contact-sharing-recognizer-api.hf.space/detect_contact"
|
29 |
+
|
30 |
+
for text in test_texts:
|
31 |
+
payload = {"text": text}
|
32 |
+
headers = {"Content-Type": "application/json"}
|
33 |
+
|
34 |
+
response = requests.post(url, data=json.dumps(payload), headers=headers)
|
35 |
+
|
36 |
+
if response.status_code == 200:
|
37 |
+
result = response.json()
|
38 |
+
print(f"Text: {result['text']}")
|
39 |
+
print(f"Contact Probability: {result['contact_probability']:.4f}")
|
40 |
+
print(f"Is Contact Info: {result['is_contact_info']}")
|
41 |
+
print("---")
|
42 |
+
else:
|
43 |
+
print(f"Error for text: {text}")
|
44 |
+
print(f"Status code: {response.status_code}")
|
45 |
+
print(f"Response: {response.text}")
|
46 |
+
print("---")
|