Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import random
|
|
2 |
from gradio_client import Client
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# List of available servers
|
6 |
servers = [
|
7 |
"BICORP/GOGOGOGO",
|
8 |
"BICORP/server-2",
|
@@ -13,10 +13,11 @@ servers = [
|
|
13 |
|
14 |
# Function to call the API with error handling
|
15 |
def call_api(message, model, preset):
|
16 |
-
selected_server = random.choice(servers)
|
17 |
-
client = Client(selected_server)
|
18 |
-
|
19 |
try:
|
|
|
20 |
result = client.predict(
|
21 |
message=message,
|
22 |
param_2=model,
|
@@ -27,90 +28,119 @@ def call_api(message, model, preset):
|
|
27 |
except Exception as e:
|
28 |
return f"Error: {str(e)}"
|
29 |
|
30 |
-
#
|
31 |
-
def toggle_theme(dark_mode):
|
32 |
-
return "dark-mode" if dark_mode else "light-mode"
|
33 |
-
|
34 |
-
# Custom CSS
|
35 |
css = """
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
color: #
|
|
|
|
|
42 |
}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
}
|
53 |
|
54 |
-
.
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
border-radius: 8px;
|
59 |
-
padding: 8px 16px;
|
60 |
-
transition: 0.3s;
|
61 |
}
|
62 |
|
63 |
-
.
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
|
67 |
-
.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
74 |
|
75 |
-
|
76 |
-
background-color:
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
padding: 15px;
|
83 |
-
border-radius: 8px;
|
84 |
}
|
85 |
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
88 |
}
|
89 |
"""
|
90 |
|
|
|
|
|
|
|
|
|
91 |
# Create Gradio interface
|
92 |
def create_interface():
|
93 |
with gr.Blocks(css=css) as demo:
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
101 |
submit_btn = gr.Button("➤", elem_id="send-button")
|
102 |
|
103 |
-
|
104 |
-
|
105 |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
|
106 |
-
model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base")
|
107 |
-
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
|
108 |
-
|
109 |
|
110 |
-
#
|
111 |
-
|
112 |
|
113 |
-
|
|
|
114 |
|
115 |
return demo
|
116 |
|
|
|
2 |
from gradio_client import Client
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# List of available servers (replace with actual server endpoints)
|
6 |
servers = [
|
7 |
"BICORP/GOGOGOGO",
|
8 |
"BICORP/server-2",
|
|
|
13 |
|
14 |
# Function to call the API with error handling
|
15 |
def call_api(message, model, preset):
|
16 |
+
selected_server = random.choice(servers) # Randomly select a server
|
17 |
+
client = Client(selected_server) # Create a client for the selected server
|
18 |
+
|
19 |
try:
|
20 |
+
# Call the /chat endpoint with the provided parameters
|
21 |
result = client.predict(
|
22 |
message=message,
|
23 |
param_2=model,
|
|
|
28 |
except Exception as e:
|
29 |
return f"Error: {str(e)}"
|
30 |
|
31 |
+
# Custom CSS for styling
|
|
|
|
|
|
|
|
|
32 |
css = """
|
33 |
+
/* Light Mode */
|
34 |
+
:root {
|
35 |
+
--bg-color: #ffffff;
|
36 |
+
--text-color: #333;
|
37 |
+
--input-bg: #f8f8f8;
|
38 |
+
--border-color: #ddd;
|
39 |
+
--button-bg: #007bff;
|
40 |
+
--button-text: white;
|
41 |
}
|
42 |
|
43 |
+
/* Dark Mode */
|
44 |
+
[data-theme='dark'] {
|
45 |
+
--bg-color: #1e1e1e;
|
46 |
+
--text-color: #f8f8f8;
|
47 |
+
--input-bg: #333;
|
48 |
+
--border-color: #555;
|
49 |
+
--button-bg: #0d6efd;
|
50 |
+
--button-text: white;
|
51 |
}
|
52 |
|
53 |
+
body {
|
54 |
+
background-color: var(--bg-color);
|
55 |
+
color: var(--text-color);
|
56 |
}
|
57 |
|
58 |
+
.gradio-container {
|
59 |
+
max-width: 600px;
|
60 |
+
margin: auto;
|
61 |
+
padding: 20px;
|
|
|
|
|
|
|
62 |
}
|
63 |
|
64 |
+
.chatbox {
|
65 |
+
border: 1px solid var(--border-color);
|
66 |
+
border-radius: 10px;
|
67 |
+
padding: 10px;
|
68 |
+
background-color: var(--input-bg);
|
69 |
+
min-height: 300px;
|
70 |
+
overflow-y: auto;
|
71 |
}
|
72 |
|
73 |
+
.input-row {
|
74 |
+
display: flex;
|
75 |
+
align-items: center;
|
76 |
+
border: 1px solid var(--border-color);
|
77 |
+
border-radius: 10px;
|
78 |
+
padding: 5px;
|
79 |
+
background-color: var(--input-bg);
|
80 |
+
}
|
81 |
+
|
82 |
+
#message-input {
|
83 |
+
flex-grow: 1;
|
84 |
+
border: none;
|
85 |
+
background: transparent;
|
86 |
+
color: var(--text-color);
|
87 |
}
|
88 |
|
89 |
+
#send-button {
|
90 |
+
background-color: var(--button-bg);
|
91 |
+
color: var(--button-text);
|
92 |
+
border-radius: 50%;
|
93 |
+
width: 40px;
|
94 |
+
height: 40px;
|
95 |
+
display: flex;
|
96 |
+
align-items: center;
|
97 |
+
justify-content: center;
|
98 |
}
|
99 |
|
100 |
+
#send-button:hover {
|
101 |
+
opacity: 0.8;
|
|
|
|
|
102 |
}
|
103 |
|
104 |
+
#settings-container {
|
105 |
+
border: 1px solid var(--border-color);
|
106 |
+
border-radius: 10px;
|
107 |
+
padding: 10px;
|
108 |
+
margin-top: 10px;
|
109 |
}
|
110 |
"""
|
111 |
|
112 |
+
# Function to toggle dark mode
|
113 |
+
def toggle_dark_mode(mode):
|
114 |
+
return gr.update(theme="dark" if mode else "default")
|
115 |
+
|
116 |
# Create Gradio interface
|
117 |
def create_interface():
|
118 |
with gr.Blocks(css=css) as demo:
|
119 |
+
gr.Markdown("## 💬 Chatbot")
|
120 |
+
|
121 |
+
# Chatbox
|
122 |
+
chat_output = gr.HTML("", elem_classes="chatbox")
|
123 |
+
|
124 |
+
# Input container for message and send button
|
125 |
+
with gr.Row(elem_classes="input-row"):
|
126 |
+
message = gr.Textbox(
|
127 |
+
placeholder="Type a message...",
|
128 |
+
show_label=False,
|
129 |
+
elem_id="message-input"
|
130 |
+
)
|
131 |
submit_btn = gr.Button("➤", elem_id="send-button")
|
132 |
|
133 |
+
# Settings Panel
|
|
|
134 |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
|
135 |
+
model = gr.Dropdown(choices=["Lake 1 Base"], label="Select Model", value="Lake 1 Base")
|
136 |
+
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Select Preset", value="Fast")
|
137 |
+
dark_mode = gr.Checkbox(label="Dark Mode", value=False)
|
138 |
|
139 |
+
# Button click event
|
140 |
+
submit_btn.click(call_api, inputs=[message, model, preset], outputs=chat_output)
|
141 |
|
142 |
+
# Toggle dark mode
|
143 |
+
dark_mode.change(toggle_dark_mode, inputs=[dark_mode])
|
144 |
|
145 |
return demo
|
146 |
|