Download app.py from ericjedha/spammy: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/ericjedha/spammy/resolve/main/app.py
- Command line
-
hf download hf://spaces/ericjedha/spammy/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ericjedha/spammy/resolve/main/app.py
1.05 kB
| import gradio as gr | |
| from transformers import pipeline | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| def check_spam(text): | |
| classifier = pipeline("text-classification") | |
| model_name = "ericjedha/spammy_overfit" #ModernBert | |
| model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| classifier = pipeline("text-classification", model = model, tokenizer = tokenizer) | |
| result = classifier(text)[0] # Récupère le premier résultat | |
| return f"Label: {result['label']}, Score: {result['score']:.2f}" # Formatage du résultat | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| with gr.Column(): | |
| sms = gr.Textbox(label="SMS à checker") | |
| spam_check_btn = gr.Button("Check") | |
| with gr.Column(): # Correction de l'indentation | |
| result = gr.Textbox(label="Résultat") | |
| spam_check_btn.click(check_spam, inputs=sms, outputs=result) # Correction de `input` -> `inputs` | |
| demo.launch(share=True) | |