Spaces:
Sleeping
Sleeping
File size: 2,516 Bytes
c489fd1 a710c69 c489fd1 a710c69 c489fd1 dc63802 de73e4c c489fd1 1df1cdd c489fd1 47b6ea0 a710c69 c489fd1 47b6ea0 de73e4c a710c69 47b6ea0 6a98d1a 47b6ea0 9f94225 a710c69 c7fd7e0 dc63802 47b6ea0 c489fd1 6a98d1a 47b6ea0 79cb1bc c489fd1 a710c69 c489fd1 de9a8d2 |
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 |
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)}"
# Dark mode CSS
dark_css = """
.gradio-container {
background-color: #1e1e1e; /* Dark background */
color: white; /* Light text color */
}
#chatbox {
background-color: #2e2e2e; /* Dark chatbox */
color: white; /* Light text color */
}
"""
# Function to toggle dark mode
def toggle_dark_mode(is_dark):
return dark_css if is_dark else ""
# Create Gradio interface
def create_interface():
with gr.Blocks(css=dark_css) as demo:
gr.Markdown("## 💬 Chatbot")
# Chat display area
chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12)
# Input area
with gr.Row():
user_input = gr.Textbox(label="Type your message here...", placeholder="Enter your message...", interactive=True)
send_button = gr.Button("Send")
# Settings section
with gr.Accordion("⚙️ Settings", open=False):
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)
# Change CSS based on dark mode toggle
dark_mode.change(lambda x: demo.css.update(toggle_dark_mode(x)), inputs=[dark_mode])
# Define the action for the send button
def send_message(message):
if message:
response = call_api(message, model.value, preset.value)
return f"You: {message}\nBot: {response}"
return ""
# Connect the send button to the send_message function
send_button.click(send_message, inputs=user_input, outputs=chatbox)
return demo
# Launch the interface
if __name__ == "__main__":
interface = create_interface()
interface.launch() |