Spaces:
Runtime error
Runtime error
streetyogi
commited on
Commit
·
3e848f0
1
Parent(s):
12a9883
Update inference_server.py
Browse files- inference_server.py +7 -1
inference_server.py
CHANGED
@@ -4,6 +4,7 @@ import uvicorn
|
|
4 |
from fastapi import FastAPI
|
5 |
import transformers
|
6 |
import torch
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
@@ -16,9 +17,14 @@ model.eval()
|
|
16 |
# Load the BERT tokenizer
|
17 |
tokenizer = transformers.BertTokenizer.from_pretrained('bert-base-cased')
|
18 |
def predict(input_text: str):
|
19 |
-
#
|
20 |
with open('strings.txt','a') as f:
|
|
|
|
|
|
|
21 |
f.write(input_text + '\n')
|
|
|
|
|
22 |
|
23 |
# Read all the strings from the file
|
24 |
with open('strings.txt', 'r') as f:
|
|
|
4 |
from fastapi import FastAPI
|
5 |
import transformers
|
6 |
import torch
|
7 |
+
import fcntl
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
|
|
17 |
# Load the BERT tokenizer
|
18 |
tokenizer = transformers.BertTokenizer.from_pretrained('bert-base-cased')
|
19 |
def predict(input_text: str):
|
20 |
+
# Open the file in append mode
|
21 |
with open('strings.txt','a') as f:
|
22 |
+
# Lock the file
|
23 |
+
fcntl.flock(f, fcntl.LOCK_EX)
|
24 |
+
# Add the new input string to the file
|
25 |
f.write(input_text + '\n')
|
26 |
+
# Unlock the file
|
27 |
+
fcntl.flock(f, fcntl.LOCK_UN)
|
28 |
|
29 |
# Read all the strings from the file
|
30 |
with open('strings.txt', 'r') as f:
|