File size: 1,076 Bytes
2d11cde
33bc31b
 
 
2d11cde
 
 
 
 
 
33bc31b
2d11cde
 
 
33bc31b
2d11cde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from backend import generate_response, add_text, calc_cost, transcribe


with gr.Blocks() as demo:
    chatbot = gr.Chatbot()

    with gr.Row():
        with gr.Column(scale=0.9):
            message = gr.Textbox(
                label="\n",
                placeholder="Please enter a message and press Enter",
            )

        with gr.Column(scale=0.05):
            cost_view = gr.Number(label="Usage in $", value=0)

    clear = gr.ClearButton([chatbot, message, cost_view])
    models = gr.Radio(
        value="gpt-3.5-turbo",
        choices=["gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-16k"],
        label="Models",
        info="Which openai chat model to use",
    )

    response = (
        message.submit(add_text, [message, chatbot], [message, chatbot], queue=False)
        .then(generate_response, [chatbot, models], chatbot)
        .then(calc_cost, outputs=cost_view)
    )

    response.then(lambda: gr.update(interactive=True), None, [message], queue=False)

demo.queue()

if __name__ == "__main__":
    demo.launch()