Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,83 +1,70 @@
|
|
1 |
import random
|
2 |
-
from gradio_client import Client
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
-
# List of
|
6 |
servers = [
|
7 |
-
"BICORP/GOGOGOGO",
|
8 |
-
"BICORP/server-2",
|
9 |
-
"BICORP/server-3",
|
10 |
-
"BICORP/server-4",
|
11 |
-
"BICORP/server-5"
|
|
|
12 |
]
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
result = client.predict(
|
21 |
-
message,
|
22 |
-
model,
|
23 |
-
preset,
|
24 |
-
api_name="/chat"
|
25 |
-
)
|
26 |
-
return result
|
27 |
-
except Exception as e:
|
28 |
-
return f"Error: {str(e)}"
|
29 |
-
|
30 |
-
# Dark mode CSS
|
31 |
-
dark_css = """
|
32 |
-
.gradio-container {
|
33 |
-
background-color: #1e1e1e; /* Dark background */
|
34 |
-
color: white; /* Light text color */
|
35 |
}
|
36 |
-
#chatbox {
|
37 |
-
background-color: #2e2e2e; /* Dark chatbox */
|
38 |
-
color: white; /* Light text color */
|
39 |
-
}
|
40 |
-
"""
|
41 |
-
|
42 |
-
# Function to toggle dark mode
|
43 |
-
def toggle_dark_mode(is_dark):
|
44 |
-
return dark_css if is_dark else ""
|
45 |
|
46 |
-
#
|
47 |
-
def
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
|
62 |
-
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
|
63 |
-
dark_mode = gr.Checkbox(label="Enable Dark Mode", value=False)
|
64 |
|
65 |
-
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
if message:
|
71 |
-
response = call_api(message, model.value, preset.value)
|
72 |
-
return f"You: {message}\nBot: {response}"
|
73 |
-
return ""
|
74 |
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
# Launch the interface
|
81 |
if __name__ == "__main__":
|
82 |
-
|
83 |
-
interface.launch()
|
|
|
1 |
import random
|
|
|
2 |
import gradio as gr
|
3 |
+
from gradio_client import Client
|
4 |
|
5 |
+
# List of server endpoints
|
6 |
servers = [
|
7 |
+
"BICORP/GOGOGOGO", # Server 1
|
8 |
+
"BICORP/server-2", # Server 2
|
9 |
+
"BICORP/server-3", # Server 3
|
10 |
+
"BICORP/server-4", # Server 4
|
11 |
+
"BICORP/server-5", # Server 5
|
12 |
+
"BICORP/server-6" # Server 6
|
13 |
]
|
14 |
|
15 |
+
# Define presets for each model
|
16 |
+
presets = {
|
17 |
+
"Fast": "Fast",
|
18 |
+
"Normal": "Normal",
|
19 |
+
"Quality": "Quality",
|
20 |
+
"Unreal Performance": "Unreal Performance"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Function to respond to user input
|
24 |
+
def respond(message, history: list, selected_model, selected_preset):
|
25 |
+
# Randomly select a server
|
26 |
+
server = random.choice(servers)
|
27 |
+
client = Client(server)
|
28 |
|
29 |
+
# Ensure history is a list of dictionaries
|
30 |
+
messages = [{"role": "user", "content": message}]
|
31 |
|
32 |
+
# Get the response from the model
|
33 |
+
try:
|
34 |
+
response = client.predict(
|
35 |
+
message=message, # Required parameter
|
36 |
+
param_2=selected_model, # Model selection
|
37 |
+
param_3=selected_preset, # Preset selection
|
38 |
+
api_name="/chat" # Ensure this is the correct API endpoint
|
39 |
+
)
|
40 |
|
41 |
+
return response # Return the response
|
42 |
+
except Exception as e:
|
43 |
+
return f"Error: {str(e)}" # Return the error message
|
|
|
|
|
44 |
|
45 |
+
# Model names and their pseudonyms
|
46 |
+
model_choices = [
|
47 |
+
("Lake 1 Base", "Lake 1 Base") # Only one model as per your example
|
48 |
+
]
|
49 |
|
50 |
+
# Convert pseudonyms to model names for the dropdown
|
51 |
+
pseudonyms = [model[0] for model in model_choices]
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
# Function to handle model selection and pseudonyms
|
54 |
+
def respond_with_pseudonym(message, history: list, selected_model, selected_preset):
|
55 |
+
# Call the existing respond function
|
56 |
+
response = respond(message, history, selected_model, selected_preset)
|
57 |
+
|
58 |
+
return response
|
59 |
|
60 |
+
# Gradio Chat Interface
|
61 |
+
demo = gr.ChatInterface(
|
62 |
+
fn=respond_with_pseudonym,
|
63 |
+
additional_inputs=[
|
64 |
+
gr.Dropdown(choices=pseudonyms, label="Select Model", value=pseudonyms[0]), # Pseudonym selection dropdown
|
65 |
+
gr.Dropdown(choices=list(presets.keys()), label="Select Preset", value="Fast") # Preset selection dropdown
|
66 |
+
],
|
67 |
+
)
|
68 |
|
|
|
69 |
if __name__ == "__main__":
|
70 |
+
demo.launch()
|
|