BICORP commited on
Commit
9f94225
·
verified ·
1 Parent(s): 48aec90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -62
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 (replace with actual server endpoints)
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) # 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,103 +27,89 @@ def call_api(message, model, preset):
28
  except Exception as e:
29
  return f"Error: {str(e)}"
30
 
31
- # Custom CSS for styling
 
 
 
 
32
  css = """
33
- .gradio-container {
34
- background-color: #121212;
35
  font-family: 'Inter', sans-serif;
36
  padding: 25px;
37
  border-radius: 12px;
38
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
 
 
 
 
39
  color: #FFFFFF;
40
  }
41
 
42
  h2 {
43
- color: #E0E0E0;
44
  text-align: center;
45
  margin-bottom: 15px;
46
  }
47
 
48
- .input-container {
49
- display: flex;
50
- align-items: center;
51
- justify-content: space-between;
52
- gap: 10px;
53
- }
54
-
55
  .gr-button {
56
  background-color: #1E88E5;
57
  color: white;
58
  font-weight: bold;
59
- border: none;
60
  border-radius: 8px;
61
  padding: 8px 16px;
62
- transition: background-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
63
  }
64
 
65
  .gr-button:hover {
66
  background-color: #1565C0;
67
- box-shadow: 0 4px 8px rgba(21, 101, 192, 0.3);
68
  }
69
 
70
  .response-box {
71
- background-color: #1E1E1E;
72
- border: 1px solid #333;
73
  border-radius: 8px;
74
  padding: 15px;
75
- margin-top: 15px;
76
- box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
77
- height: 250px; /* Fixed height for response area */
78
- overflow-y: auto; /* Scroll if content exceeds height */
79
  }
80
 
81
- .settings-container {
82
- margin-top: 25px;
83
  background-color: #1E1E1E;
84
  border: 1px solid #333;
85
- border-radius: 8px;
 
 
 
86
  padding: 15px;
87
- box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
 
 
 
 
88
  }
89
  """
90
 
91
  # Create Gradio interface
92
  def create_interface():
93
  with gr.Blocks(css=css) as demo:
94
- gr.Markdown("## Chat with Random Server")
95
-
96
- # Input container for message and send button
97
- with gr.Row(elem_id="input-container"):
98
- message = gr.Textbox(
99
- label="Message",
100
- placeholder="Type your message here...",
101
- elem_id="message-input",
102
- lines=1
103
- )
104
- submit_btn = gr.Button("Send", elem_id="send-button")
105
-
106
- output = gr.Textbox(
107
- label="Response",
108
- interactive=False,
109
- elem_id="response-box",
110
- lines=10,
111
- show_label=False
112
- )
113
-
114
- # Settings section
115
  with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
116
- model = gr.Dropdown(
117
- choices=["Lake 1 Base"],
118
- label="Select Model",
119
- value="Lake 1 Base"
120
- )
121
- preset = gr.Dropdown(
122
- choices=["Fast", "Normal", "Quality", "Unreal Performance"],
123
- label="Select Preset",
124
- value="Fast"
125
- )
126
-
127
- # Button click event with loading indicator
128
  submit_btn.click(call_api, inputs=[message, model, preset], outputs=output)
129
 
130
  return demo
 
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
+ # Function to toggle dark mode
31
+ def toggle_theme(dark_mode):
32
+ return "dark-mode" if dark_mode else "light-mode"
33
+
34
+ # Custom CSS
35
  css = """
36
+ .light-mode .gradio-container {
37
+ background-color: #FFFFFF;
38
  font-family: 'Inter', sans-serif;
39
  padding: 25px;
40
  border-radius: 12px;
41
+ color: #000000;
42
+ }
43
+
44
+ .dark-mode .gradio-container {
45
+ background-color: #121212;
46
  color: #FFFFFF;
47
  }
48
 
49
  h2 {
 
50
  text-align: center;
51
  margin-bottom: 15px;
52
  }
53
 
 
 
 
 
 
 
 
54
  .gr-button {
55
  background-color: #1E88E5;
56
  color: white;
57
  font-weight: bold;
 
58
  border-radius: 8px;
59
  padding: 8px 16px;
60
+ transition: 0.3s;
61
  }
62
 
63
  .gr-button:hover {
64
  background-color: #1565C0;
 
65
  }
66
 
67
  .response-box {
68
+ background-color: #F9F9F9;
 
69
  border-radius: 8px;
70
  padding: 15px;
71
+ height: 250px;
72
+ overflow-y: auto;
 
 
73
  }
74
 
75
+ .dark-mode .response-box {
 
76
  background-color: #1E1E1E;
77
  border: 1px solid #333;
78
+ }
79
+
80
+ .settings-container {
81
+ margin-top: 20px;
82
  padding: 15px;
83
+ border-radius: 8px;
84
+ }
85
+
86
+ .dark-mode .settings-container {
87
+ background-color: #1E1E1E;
88
  }
89
  """
90
 
91
  # Create Gradio interface
92
  def create_interface():
93
  with gr.Blocks(css=css) as demo:
94
+ dark_mode = gr.State(False) # Store dark mode state
95
+
96
+ with gr.Row():
97
+ gr.Markdown("## 💬 Chatbot", elem_classes=["chat-title"])
98
+
99
+ with gr.Row():
100
+ message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1)
101
+ submit_btn = gr.Button("➤", elem_id="send-button")
102
+
103
+ output = gr.Textbox(interactive=False, elem_id="response-box", lines=10, show_label=False)
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
+ dark_mode_toggle = gr.Checkbox(label="Dark Mode", value=False)
109
+
110
+ # Apply dark mode toggle
111
+ dark_mode_toggle.change(toggle_theme, inputs=[dark_mode_toggle], outputs=[demo])
112
+
 
 
 
 
 
113
  submit_btn.click(call_api, inputs=[message, model, preset], outputs=output)
114
 
115
  return demo