Spaces:
Sleeping
Sleeping
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: | |
# **Get API parameter names (replace with actual API parameter names from "View API")** | |
result = client.predict( | |
message, # First input | |
model, # Second input (correct parameter name) | |
preset, # Third input (correct parameter name) | |
api_name="/chat" | |
) | |
return result | |
except Exception as e: | |
return f"Error: {str(e)}" | |
# **Custom CSS for clean UI** | |
css = """ | |
.gradio-container { | |
background-color: #f9f9f9; | |
font-family: 'Arial', sans-serif; | |
padding: 20px; | |
} | |
#chatbox { | |
background-color: white; | |
border-radius: 10px; | |
padding: 15px; | |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | |
height: 400px; | |
overflow-y: auto; | |
} | |
#input-container { | |
display: flex; | |
align-items: center; | |
border: 1px solid #ccc; | |
border-radius: 20px; | |
padding: 5px; | |
background-color: white; | |
} | |
#message-input { | |
flex-grow: 1; | |
border: none; | |
padding: 10px; | |
font-size: 14px; | |
outline: none; | |
} | |
#send-button { | |
border: none; | |
background: none; | |
cursor: pointer; | |
padding: 10px; | |
} | |
#send-button:hover { | |
opacity: 0.7; | |
} | |
#settings-container { | |
margin-top: 20px; | |
} | |
""" | |
# **Create Gradio interface** | |
def create_interface(): | |
with gr.Blocks(css=css) as demo: | |
gr.Markdown("## 💬 Chatbot") | |
# **Chat display area** | |
chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12) | |
# **Input field with button inside** | |
with gr.Row(elem_id="input-container"): | |
message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1, show_label=False) | |
send_btn = gr.Button("➤", elem_id="send-button") | |
# **Settings section** | |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"): | |
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) | |
# **Button click event** | |
send_btn.click(call_api, inputs=[message, model, preset], outputs=chatbox) | |
return demo | |
# **Launch the interface** | |
if __name__ == "__main__": | |
interface = create_interface() | |
interface.launch() |