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,11 +13,10 @@ 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 |
-
# Call the /chat endpoint with the provided parameters
|
21 |
result = client.predict(
|
22 |
message=message,
|
23 |
param_2=model,
|
@@ -28,119 +27,77 @@ def call_api(message, model, preset):
|
|
28 |
except Exception as e:
|
29 |
return f"Error: {str(e)}"
|
30 |
|
31 |
-
# Custom CSS for
|
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 |
-
|
60 |
-
|
61 |
padding: 20px;
|
62 |
}
|
63 |
|
64 |
-
|
65 |
-
|
66 |
border-radius: 10px;
|
67 |
-
padding:
|
68 |
-
|
69 |
-
|
70 |
overflow-y: auto;
|
71 |
}
|
72 |
|
73 |
-
|
74 |
display: flex;
|
75 |
align-items: center;
|
76 |
-
border: 1px solid
|
77 |
-
border-radius:
|
78 |
padding: 5px;
|
79 |
-
background-color:
|
80 |
}
|
81 |
|
82 |
#message-input {
|
83 |
flex-grow: 1;
|
84 |
border: none;
|
85 |
-
|
86 |
-
|
|
|
87 |
}
|
88 |
|
89 |
#send-button {
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
height: 40px;
|
95 |
-
display: flex;
|
96 |
-
align-items: center;
|
97 |
-
justify-content: center;
|
98 |
}
|
99 |
|
100 |
#send-button:hover {
|
101 |
-
opacity: 0.
|
102 |
}
|
103 |
|
104 |
#settings-container {
|
105 |
-
|
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 |
-
#
|
122 |
-
|
123 |
|
124 |
-
# Input
|
125 |
-
with gr.Row(
|
126 |
-
message = gr.Textbox(
|
127 |
-
|
128 |
-
show_label=False,
|
129 |
-
elem_id="message-input"
|
130 |
-
)
|
131 |
-
submit_btn = gr.Button("➤", elem_id="send-button")
|
132 |
|
133 |
-
# Settings
|
134 |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
|
135 |
-
model = gr.Dropdown(choices=["Lake 1 Base"], label="
|
136 |
-
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="
|
137 |
-
dark_mode = gr.Checkbox(label="Dark Mode", value=False)
|
138 |
|
139 |
# Button click event
|
140 |
-
|
141 |
-
|
142 |
-
# Toggle dark mode
|
143 |
-
dark_mode.change(toggle_dark_mode, inputs=[dark_mode])
|
144 |
|
145 |
return demo
|
146 |
|
|
|
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 |
|
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 |
except Exception as e:
|
28 |
return f"Error: {str(e)}"
|
29 |
|
30 |
+
# Custom CSS for modern UI
|
31 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
.gradio-container {
|
33 |
+
background-color: #f9f9f9;
|
34 |
+
font-family: 'Arial', sans-serif;
|
35 |
padding: 20px;
|
36 |
}
|
37 |
|
38 |
+
#chatbox {
|
39 |
+
background-color: white;
|
40 |
border-radius: 10px;
|
41 |
+
padding: 15px;
|
42 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
43 |
+
height: 400px;
|
44 |
overflow-y: auto;
|
45 |
}
|
46 |
|
47 |
+
#input-container {
|
48 |
display: flex;
|
49 |
align-items: center;
|
50 |
+
border: 1px solid #ccc;
|
51 |
+
border-radius: 20px;
|
52 |
padding: 5px;
|
53 |
+
background-color: white;
|
54 |
}
|
55 |
|
56 |
#message-input {
|
57 |
flex-grow: 1;
|
58 |
border: none;
|
59 |
+
padding: 10px;
|
60 |
+
font-size: 14px;
|
61 |
+
outline: none;
|
62 |
}
|
63 |
|
64 |
#send-button {
|
65 |
+
border: none;
|
66 |
+
background: none;
|
67 |
+
cursor: pointer;
|
68 |
+
padding: 10px;
|
|
|
|
|
|
|
|
|
69 |
}
|
70 |
|
71 |
#send-button:hover {
|
72 |
+
opacity: 0.7;
|
73 |
}
|
74 |
|
75 |
#settings-container {
|
76 |
+
margin-top: 20px;
|
|
|
|
|
|
|
77 |
}
|
78 |
"""
|
79 |
|
|
|
|
|
|
|
|
|
80 |
# Create Gradio interface
|
81 |
def create_interface():
|
82 |
with gr.Blocks(css=css) as demo:
|
83 |
gr.Markdown("## 💬 Chatbot")
|
84 |
|
85 |
+
# Chat display area
|
86 |
+
chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12)
|
87 |
|
88 |
+
# Input field with button inside
|
89 |
+
with gr.Row(elem_id="input-container"):
|
90 |
+
message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1, show_label=False)
|
91 |
+
send_btn = gr.Button("➤", elem_id="send-button")
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
# Settings section
|
94 |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
|
95 |
+
model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base")
|
96 |
+
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
|
97 |
+
dark_mode = gr.Checkbox(label="Enable Dark Mode", value=False)
|
98 |
|
99 |
# Button click event
|
100 |
+
send_btn.click(call_api, inputs=[message, model, preset], outputs=chatbox)
|
|
|
|
|
|
|
101 |
|
102 |
return demo
|
103 |
|