Erfan11 commited on
Commit
9a6b849
1 Parent(s): 7cd2c4b

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +28 -0
main.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ import torch
4
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ def load_model(model_path):
10
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
11
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
12
+ return model, tokenizer
13
+
14
+ def predict(text, model, tokenizer):
15
+ inputs = tokenizer(text, return_tensors="pt")
16
+ outputs = model(**inputs)
17
+ return outputs
18
+
19
+ def main():
20
+ model_path = os.getenv('MODEL_PATH')
21
+ model, tokenizer = load_model(model_path)
22
+ # Example usage
23
+ text = "Sample input text"
24
+ result = predict(text, model, tokenizer)
25
+ print(result)
26
+
27
+ if __name__ == "__main__":
28
+ main()