Spaces:
Sleeping
Sleeping
| import random | |
| from gradio_client import Client | |
| import gradio as gr | |
| # List of available servers | |
| servers = [ | |
| "BICORP/GOGOGOGO", | |
| "BICORP/server-2", | |
| "BICORP/server-3", | |
| "BICORP/server-4", | |
| "BICORP/server-5" | |
| ] | |
| # Function to call the API with error handling | |
| def call_api(message, model, preset): | |
| selected_server = random.choice(servers) | |
| client = Client(selected_server) | |
| try: | |
| result = client.predict( | |
| message=message, | |
| param_2=model, | |
| param_3=preset, | |
| api_name="/chat" | |
| ) | |
| return result | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Function to toggle dark mode | |
| def toggle_theme(dark_mode): | |
| return "dark-mode" if dark_mode else "light-mode" | |
| # Custom CSS | |
| css = """ | |
| .light-mode .gradio-container { | |
| background-color: #FFFFFF; | |
| font-family: 'Inter', sans-serif; | |
| padding: 25px; | |
| border-radius: 12px; | |
| color: #000000; | |
| } | |
| .dark-mode .gradio-container { | |
| background-color: #121212; | |
| color: #FFFFFF; | |
| } | |
| h2 { | |
| text-align: center; | |
| margin-bottom: 15px; | |
| } | |
| .gr-button { | |
| background-color: #1E88E5; | |
| color: white; | |
| font-weight: bold; | |
| border-radius: 8px; | |
| padding: 8px 16px; | |
| transition: 0.3s; | |
| } | |
| .gr-button:hover { | |
| background-color: #1565C0; | |
| } | |
| .response-box { | |
| background-color: #F9F9F9; | |
| border-radius: 8px; | |
| padding: 15px; | |
| height: 250px; | |
| overflow-y: auto; | |
| } | |
| .dark-mode .response-box { | |
| background-color: #1E1E1E; | |
| border: 1px solid #333; | |
| } | |
| .settings-container { | |
| margin-top: 20px; | |
| padding: 15px; | |
| border-radius: 8px; | |
| } | |
| .dark-mode .settings-container { | |
| background-color: #1E1E1E; | |
| } | |
| """ | |
| # Create Gradio interface | |
| def create_interface(): | |
| with gr.Blocks(css=css) as demo: | |
| dark_mode = gr.State(False) # Store dark mode state | |
| with gr.Row(): | |
| gr.Markdown("## 💬 Chatbot", elem_classes=["chat-title"]) | |
| with gr.Row(): | |
| message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1) | |
| submit_btn = gr.Button("➤", elem_id="send-button") | |
| output = gr.Textbox(interactive=False, elem_id="response-box", lines=10, show_label=False) | |
| with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"): | |
| model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base") | |
| preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast") | |
| dark_mode_toggle = gr.Checkbox(label="Dark Mode", value=False) | |
| # Apply dark mode toggle | |
| dark_mode_toggle.change(toggle_theme, inputs=[dark_mode_toggle], outputs=[demo]) | |
| submit_btn.click(call_api, inputs=[message, model, preset], outputs=output) | |
| return demo | |
| # Launch the interface | |
| if __name__ == "__main__": | |
| interface = create_interface() | |
| interface.launch() |