Spaces:
Sleeping
Sleeping
Download app.py from Ashybalka/it-classifier-de: direct link, hf CLI and curl.
- Browser
- Download file 4.65 kB
-
https://huggingface.co/spaces/Ashybalka/it-classifier-de/resolve/main/app.py
- Command line
-
hf download hf://spaces/Ashybalka/it-classifier-de/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Ashybalka/it-classifier-de/resolve/main/app.py
4.65 kB
| import gradio as gr | |
| from optimum.onnxruntime import ORTModelForSequenceClassification | |
| from transformers import AutoTokenizer | |
| MODEL_REPO = "Ashybalka/xlm-roberta-taxonomy-it-de" | |
| TOP_K = 5 | |
| print("Loading model...") | |
| model = ORTModelForSequenceClassification.from_pretrained( | |
| MODEL_REPO, | |
| subfolder="onnx-int8", | |
| file_name="model_quantized.onnx", | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO) | |
| id2label = model.config.id2label | |
| print(f"Loaded. {len(id2label)} classes.") | |
| def classify(title: str, description: str): | |
| title = (title or "").strip() | |
| description = (description or "").strip() | |
| if not title and not description: | |
| return {}, "Enter the job title and/or vacancy description." | |
| if title and description: | |
| text = f"{title} [SEP] {description}" | |
| else: | |
| text = title or description | |
| inputs = tokenizer( | |
| text, | |
| return_tensors="pt", | |
| truncation=True, | |
| max_length=512, | |
| padding=True, | |
| ) | |
| outputs = model(**inputs) | |
| logits = outputs.logits[0] | |
| import numpy as np | |
| logits_np = logits.numpy() if hasattr(logits, "numpy") else np.asarray(logits) | |
| exp = np.exp(logits_np - logits_np.max()) | |
| probs = exp / exp.sum() | |
| scores = {id2label[i]: float(probs[i]) for i in range(len(probs))} | |
| top_label = max(scores, key=scores.get) | |
| confidence = scores[top_label] | |
| summary = f"**{top_label}** ({confidence:.1%})" | |
| return scores, summary | |
| with gr.Blocks(title="IT Job Classifier (DE)") as demo: | |
| gr.Markdown( | |
| """ | |
| # Klassifikator für deutsche IT-Stellenanzeigen | |
| Fine-tuned **XLM-RoBERTa** (INT8 quantized, ONNX) — classifies German-language | |
| IT job postings into **14 subcategories**. | |
| **Test metrics:** Accuracy 91.7% · F1 macro 90.5% · F1 weighted 91.7% | |
| Trained on ~20,200 German job listings with 3-model LLM consensus labeling. | |
| [Model card →](https://huggingface.co/Ashybalka/xlm-roberta-taxonomy-it-de) | |
| """ | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| title_in = gr.Textbox( | |
| label="Job Title", | |
| placeholder="z.B. DevOps Engineer", | |
| lines=1, | |
| ) | |
| desc_in = gr.Textbox( | |
| label="Job Description", | |
| placeholder="z.B. Wir suchen einen erfahrenen DevOps Engineer für die Administration unserer Kubernetes-Cluster und CI/CD Pipelines...", | |
| lines=10, | |
| ) | |
| btn = gr.Button("Klassifizieren", variant="primary") | |
| with gr.Column(scale=1): | |
| top_out = gr.Markdown(label="Top prediction") | |
| scores_out = gr.Label( | |
| num_top_classes=TOP_K, | |
| label="Top categories", | |
| ) | |
| gr.Examples( | |
| examples=[ | |
| [ | |
| "DevOps Engineer", | |
| "Wir suchen einen erfahrenen DevOps Engineer für die Administration unserer Kubernetes-Cluster, Terraform-basierte Infrastruktur und CI/CD Pipelines mit GitLab. Erfahrung mit Prometheus, Grafana und AWS oder Azure erwünscht.", | |
| ], | |
| [ | |
| "Systemadministrator", | |
| "Betreuung von Linux- und Windows-Servern, Active Directory, Backup-Lösungen (Veeam), Netzwerkadministration. Erfahrung mit Ansible und Bash-Scripting von Vorteil.", | |
| ], | |
| [ | |
| "Frontend Developer", | |
| "Entwicklung moderner Single-Page-Applications mit React und TypeScript. Erfahrung mit REST APIs, Webpack und Responsive Design. Kenntnisse in CSS-in-JS wünschenswert.", | |
| ], | |
| [ | |
| "Data Engineer", | |
| "Aufbau und Wartung unserer Data Pipelines mit Apache Airflow, Spark und Kafka. Erfahrung mit PostgreSQL, Snowflake und dbt. Python-Programmierung und SQL auf Expert-Niveau.", | |
| ], | |
| [ | |
| "IT Security Specialist", | |
| "Durchführung von Penetrationstests, Schwachstellenanalysen und Security Audits. Erfahrung mit SIEM-Systemen, Incident Response und ISO 27001. CISSP oder CEH-Zertifizierung von Vorteil.", | |
| ], | |
| [ | |
| "SAP Berater", | |
| "Beratung und Implementierung von SAP S/4HANA Modulen (FI/CO). Customizing, Schulung von Key-Usern, Unterstützung im Tagesgeschäft. Erfahrung mit ABAP von Vorteil.", | |
| ], | |
| ], | |
| inputs=[title_in, desc_in], | |
| label="Beispiele", | |
| ) | |
| btn.click( | |
| fn=classify, | |
| inputs=[title_in, desc_in], | |
| outputs=[scores_out, top_out], | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |