Spaces:
Sleeping
Sleeping
File size: 3,577 Bytes
c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 48aec90 c489fd1 |
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
import random
from gradio_client import Client
import gradio as gr
# List of available servers (replace with actual server endpoints)
servers = [
"BICORP/GOGOGOGO",
"BICORP/server-2",
"BICORP/server-3",
"BICORP/server-4",
"BICORP/server-5"
]
# Function to call the API with error handling
def call_api(message, model, preset):
selected_server = random.choice(servers) # Randomly select a server
client = Client(selected_server) # Create a client for the selected server
try:
# Call the /chat endpoint with the provided parameters
result = client.predict(
message=message,
param_2=model,
param_3=preset,
api_name="/chat"
)
return result
except Exception as e:
return f"Error: {str(e)}"
# Custom CSS for styling
css = """
.gradio-container {
background-color: #121212;
font-family: 'Inter', sans-serif;
padding: 25px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
color: #FFFFFF;
}
h2 {
color: #E0E0E0;
text-align: center;
margin-bottom: 15px;
}
.input-container {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.gr-button {
background-color: #1E88E5;
color: white;
font-weight: bold;
border: none;
border-radius: 8px;
padding: 8px 16px;
transition: background-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}
.gr-button:hover {
background-color: #1565C0;
box-shadow: 0 4px 8px rgba(21, 101, 192, 0.3);
}
.response-box {
background-color: #1E1E1E;
border: 1px solid #333;
border-radius: 8px;
padding: 15px;
margin-top: 15px;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
height: 250px; /* Fixed height for response area */
overflow-y: auto; /* Scroll if content exceeds height */
}
.settings-container {
margin-top: 25px;
background-color: #1E1E1E;
border: 1px solid #333;
border-radius: 8px;
padding: 15px;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}
"""
# Create Gradio interface
def create_interface():
with gr.Blocks(css=css) as demo:
gr.Markdown("## Chat with Random Server")
# Input container for message and send button
with gr.Row(elem_id="input-container"):
message = gr.Textbox(
label="Message",
placeholder="Type your message here...",
elem_id="message-input",
lines=1
)
submit_btn = gr.Button("Send", elem_id="send-button")
output = gr.Textbox(
label="Response",
interactive=False,
elem_id="response-box",
lines=10,
show_label=False
)
# Settings section
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
model = gr.Dropdown(
choices=["Lake 1 Base"],
label="Select Model",
value="Lake 1 Base"
)
preset = gr.Dropdown(
choices=["Fast", "Normal", "Quality", "Unreal Performance"],
label="Select Preset",
value="Fast"
)
# Button click event with loading indicator
submit_btn.click(call_api, inputs=[message, model, preset], outputs=output)
return demo
# Launch the interface
if __name__ == "__main__":
interface = create_interface()
interface.launch() |