backzone1 commited on
Commit
5fcd732
·
1 Parent(s): b669844

Add application file

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,24 +1,31 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  pipe = pipeline("text-generation", model="openchat/openchat_3.5")
5
 
6
- # Prompt แบบ role-play
7
- prompt = """[INST] Extract structured data from the following message using this form:
 
8
  - วันที่ขึ้นของ
9
  - วันที่ส่งของ
10
  - ต้นทาง
11
  - ปลายทาง
12
 
13
  Message:
14
- เข้ารับของวัน พุธ ที่ 28/05/2568
15
- ส่งโหลด วัน พฤหัส ที่ 29/05/2568
16
- ห้วยกระเจา - BBL
17
- เข้ารับของวัน พฤหัส ที่ 29/05/2568
18
- ส่งโหลด วัน ศุกร์ ที่ 30/05/2568
19
- ห้วยกระเจา - BBL
20
  [/INST]
21
  """
 
 
22
 
23
- result = pipe(prompt, max_new_tokens=300, do_sample=False)
24
- print(result[0]["generated_text"])
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # โหลดโมเดล
5
  pipe = pipeline("text-generation", model="openchat/openchat_3.5")
6
 
7
+ # ฟังก์ชันประมวลผลข้อความ
8
+ def extract_fields(msg):
9
+ prompt = f"""[INST] Extract structured data from the following message using this form:
10
  - วันที่ขึ้นของ
11
  - วันที่ส่งของ
12
  - ต้นทาง
13
  - ปลายทาง
14
 
15
  Message:
16
+ {msg}
 
 
 
 
 
17
  [/INST]
18
  """
19
+ result = pipe(prompt, max_new_tokens=300, do_sample=False, temperature=0.3)
20
+ return result[0]["generated_text"]
21
 
22
+ # UI ด้วย Gradio
23
+ demo = gr.Interface(
24
+ fn=extract_fields,
25
+ inputs=gr.Textbox(lines=10, label="พิมพ์ข้อความจาก LINE"),
26
+ outputs=gr.Textbox(label="ข้อมูลที่สรุปได้"),
27
+ title="สรุปข้อมูลจากข้อความ LINE",
28
+ description="ระบบจะดึงข้อมูล วันที่ขึ้นของ, วันที่ส่งของ, ต้นทาง, ปลายทาง จากข้อความที่ได้รับ"
29
+ )
30
+
31
+ demo.launch()