File size: 876 Bytes
d9198c9
b0e6e30
89d3f1f
b0e6e30
d9198c9
 
b0e6e30
d9198c9
 
 
 
 
 
b0e6e30
d9198c9
 
 
 
 
 
 
 
 
3806dac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import gradio as gr
from transformers import pipeline

# اگر از سکرت استفاده کردی
# token = os.getenv("HF_TOKEN")

# مدل طبقه‌بندی فارسی اخبار
clf_pipeline = pipeline(
    "text-classification",
    model="HooshvareLab/bert-fa-base-uncased-clf-persiannews",
    # use_auth_token=token  # فقط اگر مدل خصوصی بود
)

def classify_text(text):
    result = clf_pipeline(text)[0]
    label = result["label"]
    score = result["score"]
    return f"برچسب: {label}\nدرصد اطمینان: {round(score * 100, 2)}٪"

iface = gr.Interface(fn=classify_text, inputs="text", outputs="text",
                     title="طبقه‌بندی اخبار فارسی",
                     description="یک متن خبری فارسی وارد کن تا مدل موضوع آن را تشخیص دهد.")
iface.launch()