saenchan commited on
Commit
1e5ff0e
·
verified ·
1 Parent(s): a18a083

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -27
app.py DELETED
@@ -1,27 +0,0 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- # โหลด Zero-Shot Classifier
5
- classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
6
-
7
- # ฟังก์ชันหลักสำหรับจัดหมวดหมู่ข้อความ
8
- def classify(text, labels):
9
- labels = [label.strip() for label in labels.split(",") if label.strip()]
10
- if not labels:
11
- return {"Error": "กรุณาใส่หมวดหมู่อย่างน้อยหนึ่งรายการ"}
12
- result = classifier(text, candidate_labels=labels)
13
- return {label: float(f"{score:.3f}") for label, score in zip(result["labels"], result["scores"])}
14
-
15
- # สร้าง Gradio UI
16
- interface = gr.Interface(
17
- fn=classify,
18
- inputs=[
19
- gr.Textbox(label="ข้อความที่ต้องการจัดหมวดหมู่", lines=2, placeholder="เช่น ฉันสนใจการออกแบบเกมและ AI"),
20
- gr.Textbox(label="หมวดหมู่ที่ต้องการทดสอบ (คั่นด้วย commlaceholder="เช่น วิทยาการคอมพิวเตอร์, ศิลปะ, วรรณกรรม")
21
- ],
22
- outputs=gr.Label(label="ผลลัพธ์การจัดหมวดหมู่"),
23
- title="Zero-Shot Text Classifier",
24
- description="แอปนี้ใช้โมเดล BART-MNLI เพื่อทำนายว่าข้อความที่ป้อนเข้ามาใกล้เคียงกับหมวดหมู่ใดมากที่สุด"
25
- )
26
-
27
- interface.launch()