File size: 4,226 Bytes
5441ba7
 
 
 
 
 
 
 
 
 
1122988
5441ba7
cff07a0
c3b745b
eda5a57
 
cff07a0
5441ba7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b07994c
 
 
 
 
 
 
 
 
5441ba7
 
 
b07994c
 
5441ba7
ba1d2f3
5441ba7
 
b07994c
5441ba7
ba1d2f3
b07994c
5441ba7
b07994c
 
5441ba7
 
 
 
b07994c
 
 
 
5441ba7
 
 
b07994c
5441ba7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## อันนี้อันจริง ใช้ huggingface
import os
from zipfile import ZipFile
from gtts import gTTS
import gradio as gr
import pandas as pd
import shutil

def generate_text(file, room):
    # อ่าน file excel
    data = pd.read_excel(file.name, header = None)  #(file.name)
    # เลือก column ที่มีชื่อ
    #   names = data[data.columns[3]].dropna().tolist()
    names = data[data.columns[1]].dropna().tolist()
    #names_only = names[1:]   
    names_only = names 
   
    # สร้าง dict ไว้เก็บ
    names_dict = {}
    # รันชื่อ ลำดับเก็บใน dict
    for index, name in enumerate(names_only, start=1):
      names_dict[index] = name
    #สร้างเสียง
      if room == "counter พยาบาล":
        tts = gTTS(text= "เรียนเชิญ " + name + " ติดต่อบริเวณ counter พยาบาลค่ะ", lang='th')
      else:
        tts = gTTS(text= "เรียนเชิญ " + name + " ที่ห้องตรวจหมายเลข " + room + " ค่ะ", lang='th')
      tts.save(name + '.mp3')
    #ทำตาราง output แรก
    df = pd.DataFrame.from_dict(names_dict, orient='index')
    df.columns = ['name']
    df['index'] = range(1, len(df) + 1)
    df = df[['index', 'name']]
    return df

def tts(df, select_name):
    namefromtable = df['name'].tolist()[int(select_name) - 1]
    file_select = namefromtable + ".mp3"
    with open(file_select) as fp:
      return namefromtable, fp.name

def tts_manual(input_name, room):
    if room == "counter พยาบาล":
        tts = gTTS(text= "เรียนเชิญ " + input_name + " ติดต่อบริเวณ counter พยาบาลค่ะ", lang='th')
    else:
        tts = gTTS(text= "เรียนเชิญ " + input_name + " ที่ห้องตรวจหมายเลข " + room + " ค่ะ", lang='th')
    tts.save(input_name + '.mp3')
    with open(input_name + '.mp3') as fp:
      return input_name, fp.name

with gr.Blocks() as demo:
    gr.Markdown(
    """
    ## OrthoPatientCall: Orthopedic Patient Name Calling System
    #โปรแกรมเรียกชื่อคนไข้หน้าห้องสำหรับห้องตรวจ
    """)
    room = gr.Radio(["1", "2", "3", "4", "5", "6","counter พยาบาล"], label="Doctor Room No.")
    with gr.Row():
        with gr.Column():
            gr.Markdown("อัปโหลดไฟล์ excel ตรงนี้")
            seed = gr.File(label="Input file excel (.xlsx)")
            
            btn = gr.Button("Generate Name List")                                    
            gr.Markdown("ใส่เฉพาะเลขลำดับ ของชื่อผู้ป่วยที่ต้องการเรียก")
            select_name = gr.Number(label="Select number of patient's name")                            
            btn2 = gr.Button("Generate Voice (จากไฟล์ excel)")
            voice_name = gr.Textbox(label = "ชื่อผู้ป่วยที่เลือก")
            voice = gr.Audio(label = 'เรียกชื่อผู้ป่วย')
            
        with gr.Column():
            gr.Markdown("พิมพ์ชื่อผู้ป่วยตรงนี้ ถ้าไม่มีอยู่ในไฟล์ excel")
            gr.Markdown("<<< ให้เลือกช่อง Doctor Room No. ด้านซ้ายมือด้วย")
            input_name = gr.Textbox(label = "พิมพ์ชื่อผู้ป่วยตรงนี้")
            btn3 = gr.Button("Generate Voice (พิมพ์เอง)")
            df_name = gr.DataFrame(label="Extracted name for selection speak", col_count=2)
        btn.click(generate_text, inputs=[seed,room], outputs=[df_name])
        btn2.click(tts, inputs=[df_name,select_name], outputs = [voice_name,voice])
        btn3.click(tts_manual, inputs=[input_name,room], outputs = [voice_name,voice])
            
if __name__ == "__main__":
    demo.launch()