Ahmadjalalib commited on
Commit
d9198c9
·
verified ·
1 Parent(s): 3806dac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1,15 +1,24 @@
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # لود مدل فارسی
5
- qa_pipeline = pipeline("question-answering", model="HooshvareLab/bert-fa-base-uncased-qa")
6
 
7
- def answer_question(context):
8
- question = "این متن از کجا آمده است؟"
9
- result = qa_pipeline(question=question, context=context)
10
- return result["answer"]
 
 
11
 
12
- iface = gr.Interface(fn=answer_question, inputs="text", outputs="text",
13
- title="تشخیص منبع حدیث",
14
- description="متنی وارد کن تا منبع یا مضمونش تحلیل بشه.")
 
 
 
 
 
 
15
  iface.launch()
 
1
+ import os
2
  import gradio as gr
3
  from transformers import pipeline
4
 
5
+ # اگر از سکرت استفاده کردی
6
+ # token = os.getenv("HF_TOKEN")
7
 
8
+ # مدل طبقه‌بندی فارسی اخبار
9
+ clf_pipeline = pipeline(
10
+ "text-classification",
11
+ model="HooshvareLab/bert-fa-base-uncased-clf-persiannews",
12
+ # use_auth_token=token # فقط اگر مدل خصوصی بود
13
+ )
14
 
15
+ def classify_text(text):
16
+ result = clf_pipeline(text)[0]
17
+ label = result["label"]
18
+ score = result["score"]
19
+ return f"برچسب: {label}\nدرصد اطمینان: {round(score * 100, 2)}٪"
20
+
21
+ iface = gr.Interface(fn=classify_text, inputs="text", outputs="text",
22
+ title="طبقه‌بندی اخبار فارسی",
23
+ description="یک متن خبری فارسی وارد کن تا مدل موضوع آن را تشخیص دهد.")
24
  iface.launch()