Commit
·
b073019
1
Parent(s):
4fe3d3f
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,65 +3,9 @@ import json
|
|
| 3 |
import asyncio
|
| 4 |
import websockets
|
| 5 |
from transformers import pipeline
|
| 6 |
-
classifier1 = pipeline("text-classification", model="ja_gi_47")
|
| 7 |
-
#classifier2 = pipeline("text-classification", model="ja_gi_71")
|
| 8 |
-
extractor1 = pipeline("text2text-generation", model="name_extract")
|
| 9 |
-
extractor2 = pipeline("text2text-generation", model="postcode_extract")
|
| 10 |
-
extractor3 = pipeline("text2text-generation", model="time_extract")
|
| 11 |
-
extractor4 = pipeline("text2text-generation", model="task_extract")
|
| 12 |
extractor5 = pipeline("text2text-generation", model="occ_extract")
|
| 13 |
|
| 14 |
|
| 15 |
-
async def time_extractor(websocket, path):
|
| 16 |
-
try:
|
| 17 |
-
while True:
|
| 18 |
-
data = await websocket.recv()
|
| 19 |
-
payload = json.loads(data)
|
| 20 |
-
intent = payload["prompt"]
|
| 21 |
-
label=extractor3(intent)[0]["generated_text"]
|
| 22 |
-
#label= time_check(dt)
|
| 23 |
-
if label=="":
|
| 24 |
-
label="No time intent detected"
|
| 25 |
-
await websocket.send(json.dumps(label))
|
| 26 |
-
except websockets.ConnectionClosed:
|
| 27 |
-
print("Connection closed")
|
| 28 |
-
async def task_extractor(websocket, path):
|
| 29 |
-
try:
|
| 30 |
-
while True:
|
| 31 |
-
data = await websocket.recv()
|
| 32 |
-
payload = json.loads(data)
|
| 33 |
-
intent = payload["prompt"]
|
| 34 |
-
label=extractor4(intent)[0]["generated_text"]
|
| 35 |
-
if label=="":
|
| 36 |
-
label="No request detected"
|
| 37 |
-
await websocket.send(json.dumps(label))
|
| 38 |
-
except websockets.ConnectionClosed:
|
| 39 |
-
print("Connection closed")
|
| 40 |
-
async def postcode_extractor(websocket, path):
|
| 41 |
-
try:
|
| 42 |
-
while True:
|
| 43 |
-
data = await websocket.recv()
|
| 44 |
-
payload = json.loads(data)
|
| 45 |
-
intent = payload["prompt"]
|
| 46 |
-
label=extractor2(intent)[0]["generated_text"]
|
| 47 |
-
|
| 48 |
-
if label.count(" ")>2:
|
| 49 |
-
label=""
|
| 50 |
-
if label=="":
|
| 51 |
-
label="No postcode detected"
|
| 52 |
-
await websocket.send(json.dumps(label))
|
| 53 |
-
except websockets.ConnectionClosed:
|
| 54 |
-
print("Connection closed")
|
| 55 |
-
async def name_extractor(websocket, path):
|
| 56 |
-
try:
|
| 57 |
-
while True:
|
| 58 |
-
data = await websocket.recv()
|
| 59 |
-
payload = json.loads(data)
|
| 60 |
-
intent = payload["prompt"]
|
| 61 |
-
label=extractor1(intent)[0]["generated_text"]
|
| 62 |
-
await websocket.send(json.dumps(label))
|
| 63 |
-
except websockets.ConnectionClosed:
|
| 64 |
-
print("Connection closed")
|
| 65 |
async def occ_extractor(websocket, path):
|
| 66 |
try:
|
| 67 |
while True:
|
|
@@ -76,32 +20,10 @@ async def occ_extractor(websocket, path):
|
|
| 76 |
print("Connection closed")
|
| 77 |
|
| 78 |
|
| 79 |
-
async def classify_intent1(websocket, path):
|
| 80 |
-
try:
|
| 81 |
-
while True:
|
| 82 |
-
data = await websocket.recv()
|
| 83 |
-
payload = json.loads(data)
|
| 84 |
-
intent = payload["prompt"]
|
| 85 |
-
label=classifier1(intent)[0]["label"]
|
| 86 |
-
await websocket.send(json.dumps(label))
|
| 87 |
-
except websockets.ConnectionClosed:
|
| 88 |
-
print("Connection closed")
|
| 89 |
async def start_server():
|
| 90 |
-
server0 = await websockets.serve(name_extractor, "0.0.0.0",8764)
|
| 91 |
-
print("Server name started")
|
| 92 |
-
server1 = await websockets.serve(classify_intent1, "0.0.0.0",8765)
|
| 93 |
-
print("Server 47 started")
|
| 94 |
server2 = await websockets.serve(occ_extractor, "0.0.0.0", 8766)
|
| 95 |
-
|
| 96 |
-
server3 = await websockets.serve(postcode_extractor, "0.0.0.0", 8763)
|
| 97 |
-
print("Server postcode started")
|
| 98 |
-
server4 = await websockets.serve(time_extractor, "0.0.0.0", 8762)
|
| 99 |
-
print("Server time started")
|
| 100 |
-
server5 = await websockets.serve(task_extractor, "0.0.0.0", 8761)
|
| 101 |
-
print("Server task started")
|
| 102 |
|
| 103 |
await asyncio.Future()
|
| 104 |
|
| 105 |
asyncio.run(start_server())
|
| 106 |
-
# await server2.wait_closed()
|
| 107 |
-
|
|
|
|
| 3 |
import asyncio
|
| 4 |
import websockets
|
| 5 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
extractor5 = pipeline("text2text-generation", model="occ_extract")
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
async def occ_extractor(websocket, path):
|
| 10 |
try:
|
| 11 |
while True:
|
|
|
|
| 20 |
print("Connection closed")
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
async def start_server():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
server2 = await websockets.serve(occ_extractor, "0.0.0.0", 8766)
|
| 25 |
+
print("Server task started")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
await asyncio.Future()
|
| 28 |
|
| 29 |
asyncio.run(start_server())
|
|
|
|
|
|