File size: 2,935 Bytes
c489fd1
 
 
 
9f94225
c489fd1
 
 
 
 
 
 
 
 
 
9f94225
 
48aec90
c489fd1
 
 
 
 
 
 
 
 
 
 
9f94225
 
 
 
 
c489fd1
9f94225
 
48aec90
 
 
9f94225
 
 
 
 
48aec90
c489fd1
 
 
 
48aec90
c489fd1
 
 
48aec90
c489fd1
48aec90
 
 
9f94225
c489fd1
 
 
48aec90
c489fd1
 
 
9f94225
48aec90
 
9f94225
 
c489fd1
 
9f94225
48aec90
 
9f94225
 
 
 
48aec90
9f94225
 
 
 
 
c489fd1
 
 
 
 
 
9f94225
 
 
 
 
 
 
 
 
 
 
48aec90
9f94225
 
 
 
 
 
 
c489fd1
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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()