Spaces:
Build error
Build error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,103 +0,0 @@
|
|
| 1 |
-
import random
|
| 2 |
-
from gradio_client import Client
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
# List of available servers (replace with actual server endpoints)
|
| 6 |
-
servers = [
|
| 7 |
-
"BICORP/GOGOGOGO",
|
| 8 |
-
"BICORP/server-2",
|
| 9 |
-
"BICORP/server-3",
|
| 10 |
-
"BICORP/server-4",
|
| 11 |
-
"BICORP/server-5"
|
| 12 |
-
]
|
| 13 |
-
|
| 14 |
-
# Function to call the API with error handling
|
| 15 |
-
def call_api(message, model, preset):
|
| 16 |
-
selected_server = random.choice(servers) # Randomly select a server
|
| 17 |
-
client = Client(selected_server) # Create a client for the selected server
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
# Call the /chat endpoint with the provided parameters
|
| 21 |
-
result = client.predict(
|
| 22 |
-
message=message,
|
| 23 |
-
param_2=model,
|
| 24 |
-
param_3=preset,
|
| 25 |
-
api_name="/chat"
|
| 26 |
-
)
|
| 27 |
-
return result
|
| 28 |
-
except Exception as e:
|
| 29 |
-
return f"Error: {str(e)}"
|
| 30 |
-
|
| 31 |
-
# Custom CSS for styling
|
| 32 |
-
css = """
|
| 33 |
-
.gradio-container {
|
| 34 |
-
background-color: #f0f0f0;
|
| 35 |
-
font-family: 'Arial', sans-serif;
|
| 36 |
-
padding: 20px;
|
| 37 |
-
border-radius: 10px;
|
| 38 |
-
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
h2 {
|
| 42 |
-
color: #333;
|
| 43 |
-
text-align: center;
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
.input-container {
|
| 47 |
-
display: flex;
|
| 48 |
-
align-items: center;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
.gr-button {
|
| 52 |
-
background-color: #4CAF50;
|
| 53 |
-
color: white;
|
| 54 |
-
border: none;
|
| 55 |
-
border-radius: 5px;
|
| 56 |
-
margin-left: 10px;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
.gr-button:hover {
|
| 60 |
-
background-color: #45a049;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
.response-box {
|
| 64 |
-
background-color: white;
|
| 65 |
-
border-radius: 5px;
|
| 66 |
-
padding: 10px;
|
| 67 |
-
margin-top: 10px;
|
| 68 |
-
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
| 69 |
-
height: 200px; /* Fixed height for response area */
|
| 70 |
-
overflow-y: auto; /* Scroll if content exceeds height */
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
.settings-container {
|
| 74 |
-
margin-top: 20px;
|
| 75 |
-
}
|
| 76 |
-
"""
|
| 77 |
-
|
| 78 |
-
# Create Gradio interface
|
| 79 |
-
def create_interface():
|
| 80 |
-
with gr.Blocks(css=css) as demo:
|
| 81 |
-
gr.Markdown("## Chat with Random Server")
|
| 82 |
-
|
| 83 |
-
# Input container for message and send button
|
| 84 |
-
with gr.Row():
|
| 85 |
-
message = gr.Textbox(label="Message", placeholder="Type your message here...", elem_id="message-input", lines=1)
|
| 86 |
-
submit_btn = gr.Button("Send", elem_id="send-button")
|
| 87 |
-
|
| 88 |
-
output = gr.Textbox(label="Response", interactive=False, elem_id="response-box", lines=5)
|
| 89 |
-
|
| 90 |
-
# Settings moved to the bottom
|
| 91 |
-
with gr.Accordion("Settings", open=False, elem_id="settings-container"):
|
| 92 |
-
model = gr.Dropdown(choices=["Model A", "Model B"], label="Select Model", value="Model A")
|
| 93 |
-
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality"], label="Select Preset", value="Fast")
|
| 94 |
-
|
| 95 |
-
# Button click event with loading indicator
|
| 96 |
-
submit_btn.click(call_api, inputs=[message, model, preset], outputs=output)
|
| 97 |
-
|
| 98 |
-
return demo
|
| 99 |
-
|
| 100 |
-
# Launch the interface
|
| 101 |
-
if __name__ == "__main__":
|
| 102 |
-
interface = create_interface()
|
| 103 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|