Spaces:
Running
Running
| # demo/app.py | |
| import gradio as gr | |
| import time | |
| from gradio_bottombar import BottomBar | |
| def chat_response(message, history): | |
| history = history or "" | |
| history += f"You: {message}\n" | |
| time.sleep(1) # Simulate thinking | |
| history += f"Bot: Thanks for the message! You said: '{message}'\n" | |
| return history, "" | |
| def update_label(value): | |
| return f"Current temperature is: {value}" | |
| with gr.Blocks(theme=gr.themes.Ocean(), title="Full Layout Demo") as demo: | |
| gr.Markdown( | |
| """ | |
| # Full Layout Demo: BottomBar with Sidebars | |
| This demo shows the `BottomBar` with `bring_to_front=True`. Notice how it now renders | |
| **on top of** the sidebars when they overlap. | |
| """ | |
| ) | |
| with BottomBar(open=False, height=180, bring_to_front=True, rounded_borders=True) as bottom_bar: | |
| with gr.Row(): | |
| message_box = gr.Textbox( | |
| show_label=False, | |
| placeholder="Type your message here...", | |
| elem_id="message-input", | |
| scale=7 | |
| ) | |
| send_button = gr.Button("Send", variant="primary", scale=1) | |
| with gr.Row(): | |
| gr.Button("Upload File") | |
| gr.Button("Record Audio") | |
| gr.ClearButton([message_box]) | |
| with gr.Row(equal_height=True): | |
| with gr.Sidebar(position="left"): | |
| gr.Markdown("### ⚙️ Settings") | |
| model_temp = gr.Slider(0, 1, value=0.7, label="Model Temperature") | |
| temp_label = gr.Markdown(update_label(0.7)) | |
| gr.CheckboxGroup( | |
| ["Enable History", "Use Profanity Filter", "Stream Response"], | |
| label="Chat Options", | |
| value=["Enable History", "Stream Response"] | |
| ) | |
| with gr.Column(scale=3): | |
| gr.Markdown("### 🤖 Chat Interface") | |
| chatbot_display = gr.Textbox( | |
| label="Chat History", | |
| lines=25, | |
| interactive=False | |
| ) | |
| with gr.Sidebar(position="right"): | |
| gr.Markdown("### ℹ️ Information") | |
| gr.Radio( | |
| ["GPT-4", "Claude 3", "Llama 3"], | |
| label="Current Model", | |
| value="Claude 3" | |
| ) | |
| gr.Dropdown( | |
| ["English", "Spanish", "Portuguese"], | |
| label="Language", | |
| value="Portuguese" | |
| ) | |
| send_button.click( | |
| fn=chat_response, | |
| inputs=[message_box, chatbot_display], | |
| outputs=[chatbot_display, message_box] | |
| ) | |
| message_box.submit( | |
| fn=chat_response, | |
| inputs=[message_box, chatbot_display], | |
| outputs=[chatbot_display, message_box] | |
| ) | |
| model_temp.change( | |
| fn=update_label, | |
| inputs=model_temp, | |
| outputs=temp_label | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |