File size: 3,761 Bytes
c489fd1
 
 
 
a710c69
c489fd1
 
 
 
 
 
 
 
a710c69
c489fd1
dc63802
 
de73e4c
c489fd1
 
1df1cdd
 
 
c489fd1
 
 
 
 
 
79cb1bc
 
de73e4c
dc63802
 
de73e4c
c489fd1
 
dc63802
 
de73e4c
dc63802
 
 
de73e4c
c489fd1
 
dc63802
de73e4c
 
dc63802
 
de73e4c
dc63802
de73e4c
 
 
 
 
dc63802
 
 
c489fd1
 
de73e4c
dc63802
 
 
79cb1bc
 
 
 
a710c69
 
9f94225
 
de73e4c
a710c69
9f94225
 
de73e4c
dc63802
c489fd1
 
 
79cb1bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a710c69
c489fd1
79cb1bc
de73e4c
 
a710c69
dc63802
de73e4c
a710c69
dc63802
 
 
9f94225
a710c69
48aec90
dc63802
 
 
9f94225
a710c69
dc63802
c489fd1
79cb1bc
 
 
c489fd1
 
a710c69
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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 correct parameters
def call_api(message, model, preset):
    selected_server = random.choice(servers)
    client = Client(selected_server)
    
    try:
        result = client.predict(
            message,
            model,
            preset,
            api_name="/chat"
        )
        return result
    except Exception as e:
        return f"Error: {str(e)}"

# Custom CSS for light mode
light_css = """
.gradio-container {
    background-color: #f9f9f9;
    font-family: 'Arial', sans-serif;
    padding: 20px;
}

#chatbox {
    background-color: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    height: 400px;
    overflow-y: auto;
}

#input-container {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 5px;
    background-color: white;
}

#message-input {
    flex-grow: 1;
    border: none;
    padding: 10px;
    font-size: 14px;
    outline: none;
}

#send-button {
    border: none;
    background: none;
    cursor: pointer;
    padding: 2px;              /* Reduced padding for a smaller button */
    font-size: 10px;           /* Smaller font size */
    width: 20px;               /* Set a specific width */
    height: 20px;              /* Set a specific height */
    color: #007BFF;            /* Text color */
    transition: opacity 0.3s;  /* Smooth transition for hover effect */
}

#send-button:hover {
    opacity: 0.7;              /* Change opacity on hover */
}

#settings-container {
    margin-top: 20px;
}
"""

# Dark mode CSS
dark_css = """
.dark-mode .gradio-container {
    background-color: #1e1e1e; /* Dark background */
    color: white;              /* Light text color */
}

.dark-mode #chatbox {
    background-color: #2e2e2e; /* Dark chatbox */
    color: white;              /* Light text color */
}

.dark-mode #input-container {
    background-color: #2e2e2e; /* Dark input container */
    border: 1px solid #444;    /* Dark border */
}

.dark-mode #message-input {
    background-color: #3e3e3e; /* Dark input field */
    color: white;              /* Light text color */
}

.dark-mode #send-button {
    color: #007BFF;            /* Button text color */
}
"""

# Create Gradio interface
def create_interface():
    with gr.Blocks() as demo:
        gr.Markdown("## 💬 Chatbot")

        # Chat display area
        chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12)

        # Input field with button inside
        with gr.Row(elem_id="input-container"):
            message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1, show_label=False)
            send_btn = gr.Button("➤", elem_id="send-button")

        # Settings section
        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 = gr.Checkbox(label="Enable Dark Mode", value=False)

        # Button click event
        send_btn.click(call_api, inputs=[message, model, preset], outputs=chatbox)

        # Toggle dark mode
        dark_mode.change(lambda x: demo.css = dark_css if x else light_css, inputs=[dark_mode])

    return demo

# Launch the interface
if __name__ == "__main__":
    interface = create_interface()
    interface.launch()