Spaces:
Sleeping
Sleeping
Download app.py from SocialScrape/html_predict: direct link, hf CLI and curl.
- Browser
- Download file 899 Bytes
-
https://huggingface.co/spaces/SocialScrape/html_predict/resolve/519d0f2bca98e7c1b413ede53a3ccc664458764d/app.py
- Command line
-
hf download hf://spaces/SocialScrape/html_predict@519d0f2bca98e7c1b413ede53a3ccc664458764d/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SocialScrape/html_predict/resolve/519d0f2bca98e7c1b413ede53a3ccc664458764d/app.py
899 Bytes
| import torch | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import gradio as gr | |
| MODEL_NAME = "SocialScrape/longformer-my-classifier" | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME) | |
| # Основна класифікаційна функція | |
| def classify_text(text): | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True) | |
| outputs = model(**inputs) | |
| probs = torch.softmax(outputs.logits, dim=-1)[0].tolist() | |
| pred_class = int(torch.argmax(outputs.logits)) | |
| return { | |
| "Predicted Class": pred_class, | |
| "Class Probabilities": probs | |
| } | |
| # Інтерфейс лише для API (без UI) | |
| iface = gr.Interface( | |
| fn=classify_text, | |
| inputs=gr.Textbox(), | |
| outputs="json", | |
| live=False | |
| ) | |
| iface.launch(show_api=True, share=False, inbrowser=False) | |