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: | |
result = client.predict( | |
message, | |
model, | |
preset, | |
api_name="/chat" | |
) | |
return result | |
except Exception as e: | |
return f"Error: {str(e)}" | |
# Create Gradio interface | |
def create_interface(): | |
with gr.Blocks() as demo: | |
gr.Markdown("## 💬 Chatbot") | |
# Chat display area | |
chatbox = gr.Textbox(label="", interactive=False, lines=12) | |
# Input box for user messages | |
user_input = gr.Textbox(label="Type your message here...", placeholder="Enter your message...", lines=1) | |
# Send button | |
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") | |
# Define the action for the send button | |
send_button.click(fn=call_api, inputs=[user_input, model, preset], outputs=chatbox) | |
return demo | |
# Launch the interface | |
if __name__ == "__main__": | |
interface = create_interface() | |
interface.launch() |