Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -46,13 +46,15 @@ class TextData(BaseModel):
|
|
46 |
text: str
|
47 |
|
48 |
# Set up logging
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
@app.post("/predict")
|
52 |
async def predict(data: TextData):
|
53 |
-
|
54 |
-
log_entry = f"{timestamp} - {data.text}"
|
55 |
-
logging.info(log_entry)
|
56 |
inputs = tokenizer(data.text, return_tensors="pt", padding=True, truncation=True)
|
57 |
inputs = {k: v.to(device1) for k, v in inputs.items()}
|
58 |
|
@@ -70,9 +72,7 @@ async def predict(data: TextData):
|
|
70 |
|
71 |
@app.post("/predict_v2")
|
72 |
async def predict_v2(data: TextData):
|
73 |
-
|
74 |
-
log_entry = f"{timestamp} - {data.text}"
|
75 |
-
logging.info(log_entry)
|
76 |
|
77 |
inputs = tokenizer(data.text, return_tensors="pt", padding=True, truncation=True)
|
78 |
inputs = {k: v.to(device2) for k, v in inputs.items()}
|
|
|
46 |
text: str
|
47 |
|
48 |
# Set up logging
|
49 |
+
def log_text(text: str):
|
50 |
+
timestamp = datetime.now().isoformat()
|
51 |
+
log_entry = f"{timestamp} - {text}\n"
|
52 |
+
with open("text_logs.txt", "a") as file:
|
53 |
+
file.write(log_entry)
|
54 |
+
|
55 |
@app.post("/predict")
|
56 |
async def predict(data: TextData):
|
57 |
+
log_text(data.text)
|
|
|
|
|
58 |
inputs = tokenizer(data.text, return_tensors="pt", padding=True, truncation=True)
|
59 |
inputs = {k: v.to(device1) for k, v in inputs.items()}
|
60 |
|
|
|
72 |
|
73 |
@app.post("/predict_v2")
|
74 |
async def predict_v2(data: TextData):
|
75 |
+
log_text(data.text)
|
|
|
|
|
76 |
|
77 |
inputs = tokenizer(data.text, return_tensors="pt", padding=True, truncation=True)
|
78 |
inputs = {k: v.to(device2) for k, v in inputs.items()}
|