Spaces:
Sleeping
Sleeping
Commit
·
b4b9f1a
1
Parent(s):
a95a3ae
Initial
Browse files- README.md +1 -0
- app.py +26 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -5,6 +5,7 @@ colorFrom: yellow
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.45.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.45.0
|
| 8 |
+
python_version: 3.12.11
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
pipe = pipeline("text-classification", model="kitrofimov/news-classifier", top_k=3)
|
| 5 |
+
|
| 6 |
+
def classify(text):
|
| 7 |
+
preds = pipe(text)[0]
|
| 8 |
+
return {p["label"]: float(p["score"]) for p in preds}
|
| 9 |
+
|
| 10 |
+
with gr.Blocks() as demo:
|
| 11 |
+
gr.Markdown("# News Classifier")
|
| 12 |
+
gr.Markdown("Paste a news article below and see which category it belongs to! (one of \"world\", \"sports\", \"business\" and \"science / technology\"")
|
| 13 |
+
gr.Markdown("This model is based on a [`distilbert-base-uncased`](https://huggingface.co/distilbert/distilbert-base-uncased) architecture and was fine-tuned on the [AG News](https://huggingface.co/datasets/fancyzhx/ag_news) dataset for 3 epochs. Training code [here](https://colab.research.google.com/drive/1KTai0S1dzwIoS3Sba_jJG9ZNISRjSKGo)")
|
| 14 |
+
|
| 15 |
+
with gr.Row():
|
| 16 |
+
with gr.Column():
|
| 17 |
+
input = gr.Textbox(lines=5, placeholder="Enter your news article...")
|
| 18 |
+
classify_btn = gr.Button("Classify")
|
| 19 |
+
with gr.Column():
|
| 20 |
+
output = gr.Label(num_top_classes=3)
|
| 21 |
+
|
| 22 |
+
classify_btn.click(classify, inputs=input, outputs=output)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|
| 25 |
+
|
| 26 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
transformers==4.56.1
|