File size: 400 Bytes
b27dfbc
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from transformers import pipeline
import csv

clf = pipeline("sentiment-analysis", model="./outputs")

def log_inference(text, prediction):
    with open("inference_log.csv", "a") as f:
        writer = csv.writer(f)
        writer.writerow([text, prediction])

text = "This is a fantastic HuggingFace project!"
result = clf(text)[0]
log_inference(text, result["label"])
print(f"{text} => {result}")