Spaces:
Sleeping
Sleeping
initial commit
Browse files- .gitignore +2 -0
- README.md +3 -0
- app.py +47 -0
- requirements.txt +59 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv/
|
| 2 |
+
.env
|
README.md
CHANGED
|
@@ -8,6 +8,9 @@ sdk_version: 6.15.2
|
|
| 8 |
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 8 |
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
base_model: google-bert/bert-base-uncased
|
| 12 |
+
datasets:
|
| 13 |
+
- sh0416/ag_news
|
| 14 |
---
|
| 15 |
|
| 16 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
labels = ['World', 'Sports', 'Business', 'Sci/Tech']
|
| 6 |
+
|
| 7 |
+
def infer(title, description):
|
| 8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
|
| 10 |
+
model_name = "mafgit/news-classifier"
|
| 11 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=4).to(device)
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
+
|
| 14 |
+
model.eval()
|
| 15 |
+
|
| 16 |
+
inputs = tokenizer(
|
| 17 |
+
title,
|
| 18 |
+
description,
|
| 19 |
+
max_length=128,
|
| 20 |
+
padding='max_length',
|
| 21 |
+
truncation=True,
|
| 22 |
+
return_tensors='pt'
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
input_ids = inputs['input_ids'].to(device)
|
| 26 |
+
attention_mask = inputs['attention_mask'].to(device)
|
| 27 |
+
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
outputs = model(
|
| 30 |
+
input_ids=input_ids,
|
| 31 |
+
attention_mask=attention_mask
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
max_idx = outputs.logits.argmax(dim=1).item()
|
| 35 |
+
output = labels[max_idx]
|
| 36 |
+
return output
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
ui = gr.Interface(
|
| 40 |
+
fn=infer,
|
| 41 |
+
inputs=["text", "text"],
|
| 42 |
+
outputs=["text"],
|
| 43 |
+
title="News Classifier",
|
| 44 |
+
description="Classify news articles into World, Sports, Business, or Sci/Tech categories."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
ui.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
annotated-doc==0.0.4
|
| 2 |
+
annotated-types==0.7.0
|
| 3 |
+
anyio==4.13.0
|
| 4 |
+
brotli==1.2.0
|
| 5 |
+
certifi==2026.5.20
|
| 6 |
+
click==8.4.1
|
| 7 |
+
colorama==0.4.6
|
| 8 |
+
fastapi==0.136.3
|
| 9 |
+
filelock==3.29.0
|
| 10 |
+
fsspec==2026.4.0
|
| 11 |
+
gradio==6.15.2
|
| 12 |
+
gradio_client==2.5.0
|
| 13 |
+
groovy==0.1.2
|
| 14 |
+
h11==0.16.0
|
| 15 |
+
hf-gradio==0.4.1
|
| 16 |
+
hf-xet==1.5.0
|
| 17 |
+
httpcore==1.0.9
|
| 18 |
+
httpx==0.28.1
|
| 19 |
+
huggingface_hub==1.17.0
|
| 20 |
+
idna==3.17
|
| 21 |
+
Jinja2==3.1.6
|
| 22 |
+
markdown-it-py==4.2.0
|
| 23 |
+
MarkupSafe==3.0.3
|
| 24 |
+
mdurl==0.1.2
|
| 25 |
+
mpmath==1.3.0
|
| 26 |
+
networkx==3.6.1
|
| 27 |
+
numpy==2.4.6
|
| 28 |
+
orjson==3.11.9
|
| 29 |
+
packaging==26.2
|
| 30 |
+
pandas==3.0.3
|
| 31 |
+
pillow==12.2.0
|
| 32 |
+
pydantic==2.13.4
|
| 33 |
+
pydantic_core==2.46.4
|
| 34 |
+
pydub==0.25.1
|
| 35 |
+
Pygments==2.20.0
|
| 36 |
+
python-dateutil==2.9.0.post0
|
| 37 |
+
python-multipart==0.0.30
|
| 38 |
+
pytz==2026.2
|
| 39 |
+
PyYAML==6.0.3
|
| 40 |
+
regex==2026.5.9
|
| 41 |
+
rich==15.0.0
|
| 42 |
+
safehttpx==0.1.7
|
| 43 |
+
safetensors==0.7.0
|
| 44 |
+
semantic-version==2.10.0
|
| 45 |
+
setuptools==81.0.0
|
| 46 |
+
shellingham==1.5.4
|
| 47 |
+
six==1.17.0
|
| 48 |
+
starlette==1.2.1
|
| 49 |
+
sympy==1.14.0
|
| 50 |
+
tokenizers==0.22.2
|
| 51 |
+
tomlkit==0.14.0
|
| 52 |
+
torch==2.12.0
|
| 53 |
+
tqdm==4.67.3
|
| 54 |
+
transformers==5.9.0
|
| 55 |
+
typer==0.25.1
|
| 56 |
+
typing-inspection==0.4.2
|
| 57 |
+
typing_extensions==4.15.0
|
| 58 |
+
tzdata==2026.2
|
| 59 |
+
uvicorn==0.48.0
|