File size: 2,119 Bytes
b1cf6ad
 
 
 
 
 
 
 
 
b2fdc53
 
 
bc6741e
 
 
 
 
 
 
 
 
 
b2fdc53
 
bc6741e
b2fdc53
 
 
 
 
 
 
 
 
 
 
 
 
bc6741e
b2fdc53
 
 
bc6741e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1cf6ad
b2fdc53
bc6741e
 
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
from gpt4all import GPT4All

# Load the GPT-4 model
model = GPT4All(model_name='orca-mini-3b.ggmlv3.q4_0.bin')

# Templates for the user prompts
prompt_template = 'USER: {0}\nASSISTANT: '

# Function to generate responses using the GPT-4 model with custom settings
def generate_response(prompt, settings):
    # Extract settings from the input
    max_tokens = settings[0]
    temp = settings[1]
    top_k = settings[2]
    top_p = settings[3]
    repeat_penalty = settings[4]
    repeat_last_n = settings[5]
    n_batch = settings[6]
    n_predict = settings[7]
    streaming = settings[8]

    # Generate chat history and input prompt
    chat_history_with_prompt = prompt_template.format(prompt)

    # Generate response with custom settings
    response = model.generate(
        chat_history_with_prompt,
        max_tokens=max_tokens,
        temp=temp,
        top_k=top_k,
        top_p=top_p,
        repeat_penalty=repeat_penalty,
        repeat_last_n=repeat_last_n,
        n_batch=n_batch,
        n_predict=n_predict,
        streaming=streaming
    )

    return response

# Initialize Gradio Interface
interface = gr.Interface(
    fn=generate_response,
    inputs=[
        gr.inputs.Textbox(label="Chat Input", placeholder="Start the conversation..."),
        gr.inputs.Number(default=200, label="Max Tokens"),
        gr.inputs.Number(default=0.7, label="Temperature"),
        gr.inputs.Number(default=40, label="Top-k"),
        gr.inputs.Number(default=0.4, label="Top-p"),
        gr.inputs.Number(default=1.18, label="Repeat Penalty"),
        gr.inputs.Number(default=64, label="Repeat Last n"),
        gr.inputs.Number(default=8, label="Batch Size"),
        gr.inputs.Textbox(default="Auto", label="Number of Predictions"),
        gr.inputs.Checkbox(default=False, label="Streaming"),
    ],
    outputs=gr.outputs.Textbox(),
    title="GPT-4 Chatbot",
    description="Chat with the GPT-4 based chatbot. Configure generation settings and see the chat history for this session.",
)

# Launch Gradio Interface
if __name__ == "__main__":
    interface.launch(debug=True)