SocialScrape commited on
Commit
519d0f2
·
verified ·
1 Parent(s): 8980326

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import gradio as gr
4
+
5
+ MODEL_NAME = "SocialScrape/longformer-my-classifier"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
9
+
10
+ # Основна класифікаційна функція
11
+ def classify_text(text):
12
+ inputs = tokenizer(text, return_tensors="pt", truncation=True)
13
+ outputs = model(**inputs)
14
+ probs = torch.softmax(outputs.logits, dim=-1)[0].tolist()
15
+ pred_class = int(torch.argmax(outputs.logits))
16
+ return {
17
+ "Predicted Class": pred_class,
18
+ "Class Probabilities": probs
19
+ }
20
+
21
+ # Інтерфейс лише для API (без UI)
22
+ iface = gr.Interface(
23
+ fn=classify_text,
24
+ inputs=gr.Textbox(),
25
+ outputs="json",
26
+ live=False
27
+ )
28
+
29
+ iface.launch(show_api=True, share=False, inbrowser=False)