File size: 1,265 Bytes
3910061
 
bb07c24
3910061
bb07c24
3910061
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import openai
import os

openai.api_key = os.environ.get("OPENAI_API_KEY")

messages = [
            {"role": "system", "content": "You are a job interviewer who will be conducting a mock interview for practice. Respond in less than 40 words."},
            ]

def transcribe(audio):
    global messages
    print(audio)

    audio_file = open(audio, "rb")
    transcript = openai.Audio.transcribe("whisper-1", audio_file)
    print(transcript)

    messages.append({"role": "user", "content": transcript["text"]})


    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages
    )
    
    system_message = response["choices"][0]["message"]["content"]

    messages.append({"role": "assistant", "content": system_message})

    chat_transcript = ""
    for message in messages:
        if message['role'] != 'system':
            chat_transcript += message['role'] + ": " + message['content'] + "\n\n"

    return chat_transcript

#with gr.Blocks() as ui:
    #advisor = gr.Image(value=config.UI_IMAGE).style(width=config.UI_IMAGE_WIDTH, height=config.UI_IMAGE_HEIGHT)
    
ui = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text").launch()

ui.launch()