Spaces:
Sleeping
Sleeping
Create main.py
Browse files
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()
|