Spaces:
Runtime error
Runtime error
| 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["max_tokens"] | |
| temp = settings["temp"] | |
| top_k = settings["top_k"] | |
| top_p = settings["top_p"] | |
| repeat_penalty = settings["repeat_penalty"] | |
| repeat_last_n = settings["repeat_last_n"] | |
| n_batch = settings["n_batch"] | |
| n_predict = settings["n_predict"] | |
| streaming = settings["streaming"] | |
| # 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 | |
| with gr.Blocks() as chatbot_demo: | |
| with gr.Tab("Chat"): | |
| gr.Interface( | |
| fn=generate_response, | |
| inputs=[ | |
| gr.inputs.Textbox(label="Chat Input", placeholder="Start the conversation..."), | |
| gr.inputs.Slider(label="Max Tokens", default=200, min_value=1, max_value=512, step=1), | |
| gr.inputs.Slider(label="Temperature", default=0.7, min_value=0.1, max_value=2.0, step=0.01), | |
| gr.inputs.Slider(label="Top-k", default=40, min_value=1, max_value=512, step=1), | |
| gr.inputs.Slider(label="Top-p", default=0.4, min_value=0.01, max_value=1.0, step=0.01), | |
| gr.inputs.Slider(label="Repeat Penalty", default=1.18, min_value=1.0, max_value=2.0, step=0.01), | |
| gr.inputs.Slider(label="Repeat Last n", default=64, min_value=1, max_value=512, step=1), | |
| gr.inputs.Slider(label="Batch Size", default=8, min_value=1, max_value=128, step=1), | |
| gr.inputs.Textbox(label="Number of Predictions", placeholder="Auto"), | |
| gr.inputs.Checkbox(label="Streaming", default=False), | |
| ], | |
| 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.", | |
| ) | |
| with gr.Tab("Settings"): | |
| # Settings UI to be defined here | |
| gr.Text("Settings tab content") | |
| # Launch Gradio Interface | |
| chatbot_demo.queue(concurrency_count=75).launch(debug=True) | |