File size: 2,434 Bytes
129bd00
 
 
224e007
129bd00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224e007
129bd00
 
 
 
224e007
 
 
 
 
 
 
 
 
 
 
 
129bd00
 
224e007
129bd00
 
224e007
129bd00
224e007
 
129bd00
224e007
 
129bd00
224e007
 
 
 
 
 
 
 
 
129bd00
 
224e007
 
 
 
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
import gradio as gr
import whisper

# Load the Whisper model
model = whisper.load_model("base")

# Define the waiter prompt in Korean.
prompt_text = """
안녕하세요, 손님!
오늘 저희 레스토랑에 방문해 주셔서 감사합니다.
저는 여러분의 웨이터입니다.
메뉴를 보시고 주문하실 음식을 결정해 주세요.
예시: "불고기와 콩나물국, 그리고 식혜 하나 부탁드립니다."
준비되셨다면, 아래의 녹음 버튼을 눌러 주문 내용을 말씀해 주세요.
"""

def process_audio(audio_file):
    if audio_file is None:
        return "오디오 파일이 없습니다. 다시 시도해 주세요."

    result = model.transcribe(audio_file, language='ko')
    transcription = result["text"].strip()
    return transcription

def evaluate_transcription(transcription):
    if transcription is None or transcription.strip() == "":
        return "입력된 내용이 없습니다."

    # Simulated GPT evaluation response.
    dummy_response = (
        "GPT 평가 결과:\n"
        "주문 내용이 전반적으로 명확합니다. "
        "더 구체적인 요청이나 추가 정보가 있으면 좋겠지만, 현재 주문은 잘 전달된 것 같습니다."
    )
    return dummy_response

with gr.Blocks() as demo:
    gr.Markdown("## 한국어 주문 녹음 앱")

    # Embed the animated GIF for the waiter animation.
    gr.Image(value="https://s13.gifyu.com/images/b2NQh.gif", label="웨이터 안내 애니메이션")

    gr.Markdown(prompt_text)

    # Audio input (without source parameter)
    audio_input = gr.Audio(type="filepath", label="녹음: 주문 내용을 말씀해 주세요")

    # Transcription output
    transcription_output = gr.Textbox(label="주문 녹취 결과", placeholder="여기에 전사 결과가 나타납니다.")

    # Evaluation output (simulated GPT feedback)
    evaluation_output = gr.Textbox(label="GPT 평가 결과", placeholder="여기에 평가 결과가 나타납니다.")

    # Buttons
    submit_btn = gr.Button("전송")
    evaluate_btn = gr.Button("평가")

    # When clicking "전송", process the audio and display the transcription.
    submit_btn.click(process_audio, inputs=audio_input, outputs=transcription_output)

    # When clicking "평가", simulate GPT's evaluation.
    evaluate_btn.click(evaluate_transcription, inputs=transcription_output, outputs=evaluation_output)

demo.launch()