Rathapoom commited on
Commit
5441ba7
·
1 Parent(s): bce7ed9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## อันนี้อันจริง ใช้ huggingface
2
+ import os
3
+ from zipfile import ZipFile
4
+ from gtts import gTTS
5
+ import gradio as gr
6
+ import pandas as pd
7
+ from google.colab import files
8
+ import shutil
9
+
10
+ def generate_text(file, room):
11
+ # อ่าน file excel
12
+ data = pd.read_excel(file.name) #(file.name)
13
+ # เลือก column ที่มีชื่อ
14
+ names = data[data.columns[3]].dropna().tolist()
15
+ names_only = names[1:]
16
+ # สร้าง dict ไว้เก็บ
17
+ names_dict = {}
18
+ # รันชื่อ ลำดับเก็บใน dict
19
+ for index, name in enumerate(names_only, start=1):
20
+ names_dict[index] = name
21
+ #สร้างเสียง
22
+ if room == "counter พยาบาล":
23
+ tts = gTTS(text= "เรียนเชิญ " + name + " ติดต่อบริเวณ counter พยาบาลค่ะ", lang='th')
24
+ else:
25
+ tts = gTTS(text= "เรียนเชิญ " + name + " ที่ห้องตรวจหมายเลข " + room + " ค่ะ", lang='th')
26
+ tts.save(name + '.mp3')
27
+ #ทำตาราง output แรก
28
+ df = pd.DataFrame.from_dict(names_dict, orient='index')
29
+ df.columns = ['name']
30
+ df['index'] = range(1, len(df) + 1)
31
+ df = df[['index', 'name']]
32
+ return df
33
+
34
+ def tts(df, select_name):
35
+ namefromtable = df['name'].tolist()[int(select_name) - 1]
36
+ file_select = namefromtable + ".mp3"
37
+ with open(file_select) as fp:
38
+ return namefromtable, fp.name
39
+
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown(
42
+ """
43
+ # OrthoPatientCall: Orthopedic Patient Name Calling System
44
+ โปรแกรมเรียกชื่อคนไข้หน้าห้องสำหรับห้องตรวจ
45
+ """)
46
+ with gr.Row():
47
+ with gr.Column():
48
+ seed = gr.File(label="Input file excel (.xlsx)")
49
+ room = gr.Radio(["1", "2", "3", "4", "5", "6","counter พยาบาล"], label="Doctor Room No.")
50
+ btn = gr.Button("Generate Name List")
51
+ gr.Markdown("ใส่เฉพาะเลขลำดับ ของชื่อผู้ป่วยที่ต้องการเรียก")
52
+ select_name = gr.Number(label="Select number of patient's name")
53
+ btn2 = gr.Button("Generate Voice")
54
+ voice_name = gr.Textbox(label = "ชื่อผู้ป่วยที่เลือก")
55
+ voice = gr.Audio(label = 'เรียกชื่อผู้ป่วย')
56
+
57
+ with gr.Column():
58
+ df_name = gr.DataFrame(label="Extracted name for selection speak", col_count=2)
59
+ btn.click(generate_text, inputs=[seed,room], outputs=[df_name])
60
+ btn2.click(tts, inputs=[df_name,select_name], outputs = [voice_name,voice])
61
+
62
+
63
+ if __name__ == "__main__":
64
+ demo.launch()