Update app.py
Browse files12345678924 unmodified lines34353637383940414243444546474849505152535455565758596061626364656667686970717273747576779 unmodified lines8788899091922 unmodified lines9596979899100101102103104105106import gradio as gr# Placeholder for model loading (adjust as needed for your specific models)# In a real application, these would load actual modelsdef load_model(model_name):print(f"Loading {model_name}...") # Indicate model loading# Simulate different model behaviors (replace with actual model logic)if model_name == "DeepSeek-R1-Distill-Qwen-32B":return lambda input_text, history: f"Distilled Model Response to: {input_text}"24 unmodified lineselse:model_function = lambda x, h: "Please select a model."# Simulate model response with parameters (replace with actual model inference)# In a real application, you would pass these parameters to your modelresponse = model_function(input_text, history)response = f"**System Message:** {system_message}\n\n**Model Response:** {response}\n\n" \f"**Parameters Used:**\n- Max New Tokens: {max_new_tokens}\n- Temperature: {temperature}\n- Top-p: {top_p}"history.append((input_text, response))return history, history, "" # Update both chatbot output and state# --- Gradio Interface ---with gr.Blocks(theme=gr.themes.Soft()) as demo: # Apply a themegr.Markdown("""# DeepSeek ChatbotCreated by [ruslanmv.com](https://ruslanmv.com/)This is a demo of different DeepSeek models. Select a model, type your message, and click "Submit".You can also adjust optional parameters like system message, max new tokens, temperature, and top-p.""")with gr.Row():with gr.Column(scale=4): # Make chatbot take more spacechatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500)msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")with gr.Row():submit_btn = gr.Button("Submit", variant="primary")clear_btn = gr.ClearButton([msg, chatbot_output])with gr.Column(scale=1):model_choice = gr.Radio(choices=["DeepSeek-R1-Distill-Qwen-32B", "DeepSeek-R1", "DeepSeek-R1-Zero"],label="Choose a Model",value="DeepSeek-R1" # Default model)with gr.Accordion("Optional Parameters", open=False):system_message = gr.Textbox(label="System Message",9 unmodified linestop_p = gr.Slider(minimum=0.10, maximum=1.00, value=0.90, label="Top-p (nucleus sampling)")# Maintain chat historychat_history = gr.State([])2 unmodified linessubmit_btn.click(chatbot,[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],[chatbot_output, chat_history, msg],)msg.submit(chatbot,[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],[chatbot_output, chat_history, msg],)# Launch the demo1234567824 unmodified lines3334353637383940414243444546474849505152535455565758596061626364656667686970717273749 unmodified lines848586878889902 unmodified lines93949596979899100101102103104import gradio as gr# Placeholder for model loading (adjust as needed for your specific models)def load_model(model_name):print(f"Loading {model_name}...")# Simulate different model behaviors (replace with actual model logic)if model_name == "DeepSeek-R1-Distill-Qwen-32B":return lambda input_text, history: f"Distilled Model Response to: {input_text}"24 unmodified lineselse:model_function = lambda x, h: "Please select a model."# Simulate model response with parametersresponse = model_function(input_text, history)# Format the response for display (without parameter details in the main chat)display_response = f"{response}"history.append((input_text, display_response))return history, history, "", model_choice, system_message, max_new_tokens, temperature, top_p # Clear input, keep other parameters# --- Gradio Interface ---with gr.Blocks(theme=gr.themes.Soft()) as demo:gr.Markdown("""# DeepSeek ChatbotCreated by [ruslanmv.com](https://ruslanmv.com/)This is a demo of different DeepSeek models. Select a model, type your message, and click "Submit".You can also adjust optional parameters like system message, max new tokens, temperature, and top-p.""")with gr.Row():with gr.Column():chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500)msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")with gr.Row():submit_btn = gr.Button("Submit", variant="primary")clear_btn = gr.ClearButton([msg, chatbot_output])# Options moved below the chat interfacewith gr.Row():with gr.Accordion("Options", open=True): # Changed label to "Options"model_choice = gr.Radio(choices=["DeepSeek-R1-Distill-Qwen-32B", "DeepSeek-R1", "DeepSeek-R1-Zero"],label="Choose a Model",value="DeepSeek-R1")with gr.Accordion("Optional Parameters", open=False):system_message = gr.Textbox(label="System Message",9 unmodified linestop_p = gr.Slider(minimum=0.10, maximum=1.00, value=0.90, label="Top-p (nucleus sampling)")# Maintain chat historychat_history = gr.State([])2 unmodified linessubmit_btn.click(chatbot,[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],[chatbot_output, chat_history, msg, model_choice, system_message, max_new_tokens, temperature, top_p],)msg.submit(chatbot,[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],[chatbot_output, chat_history, msg, model_choice, system_message, max_new_tokens, temperature, top_p],)# Launch the demo
app.py+17-19