viswanani commited on
Commit
b27dfbc
·
verified ·
1 Parent(s): 69914b2

Create src/inference.py

Browse files
Files changed (1) hide show
  1. src/inference.py +14 -0
src/inference.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import csv
3
+
4
+ clf = pipeline("sentiment-analysis", model="./outputs")
5
+
6
+ def log_inference(text, prediction):
7
+ with open("inference_log.csv", "a") as f:
8
+ writer = csv.writer(f)
9
+ writer.writerow([text, prediction])
10
+
11
+ text = "This is a fantastic HuggingFace project!"
12
+ result = clf(text)[0]
13
+ log_inference(text, result["label"])
14
+ print(f"{text} => {result}")