File size: 2,618 Bytes
02fc79d
 
7e0679d
933893f
cfb47bd
a0a3c71
02fc79d
6b26f41
d19cbee
844418d
98cb8e3
cb167f0
 
572bbdb
98cb8e3
2cd932f
d19cbee
ab2986e
 
fcf4664
77b1892
 
d348183
77b1892
ab2986e
98cb8e3
 
 
 
 
 
 
 
 
 
d7fd676
81f5fb5
 
 
0a91bcb
001968f
 
 
eaacf75
3a1624c
eaf5679
d348183
001968f
8507a80
ab2986e
 
98cb8e3
a91f0b6
c42bc9d
 
45771d5
c42bc9d
98cb8e3
d353d92
6daebf6
98cb8e3
f57f2aa
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
import gradio as gr
from gpt4all import GPT4All
from urllib.request import urlopen
import json
import time
from load_llms import model_choices, llm_intro, load_model

    
# Construct chatbot
def generate_response(model_name, message, chat_history):
    model = load_model(model_name)
    response = model.generate(message, max_tokens=100)
    chat_history.append((message, response))
    return "", chat_history

    
# Create Gradio UI
with gr.Blocks(
    css=".contain { display: flex !important; flex-direction: column !important; }"
    "#chatbot { flex-grow: 1 !important; overflow: auto !important; }"
    "#col { height: calc(100vh - 112px - 16px) !important; }"
    "#submit:hover { background-color: green !important; }"
    "#clear { background-color: darkred !important; }",
    theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Martel Sans")])                  
) as demo:
    gr.Markdown("# GPT4All Chatbot")
    with gr.Row():
        with gr.Column(scale=1):
            model_dropdown = gr.Dropdown(
                choices=model_choices(),  
                multiselect=False,
                type="value",
                value="orca-mini-3b-gguf2-q4_0.gguf",
                label="LLMs to choose from"
            )
            explanation = gr.Textbox(label="Model Description", interactive=False, value=llm_intro("orca-mini-3b-gguf2-q4_0.gguf"))
    
            # Link the dropdown with the textbox to update the description based on the selected model
            model_dropdown.change(fn=llm_intro, inputs=model_dropdown, outputs=explanation)

            gr.Gallery(label="Current Space Hardware used",             
                       value=["space_hardware.png"], 
                       type="filepath", 
                       columns=1,
                       object_fit="scale-down",
                       height=200,
                       container=False
                      )

        with gr.Column(scale=4, elem_id='col'):
            chatbot = gr.Chatbot(label="Chatroom", value=[(None, "How may I help you today?")], elem_id="chatbot")

            with gr.Row():       
                message = gr.Textbox(label="Message", scale=10)
                message.submit(generate_response, inputs=[model_dropdown, message, chatbot], outputs=[message, chatbot])
                submit_button = gr.Button("Submit", scale=1, elem_id="submit")
                submit_button.click(generate_response, inputs=[model_dropdown, message, chatbot], outputs=[message, chatbot])

            clear = gr.ClearButton([message, chatbot], elem_id="clear")

# Launch the Gradio app
demo.launch()