Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import random
|
|
2 |
from gradio_client import Client
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# List of available servers
|
6 |
servers = [
|
7 |
"BICORP/GOGOGOGO",
|
8 |
"BICORP/server-2",
|
@@ -11,13 +11,13 @@ servers = [
|
|
11 |
"BICORP/server-5"
|
12 |
]
|
13 |
|
14 |
-
# Function to call the API with correct parameters
|
15 |
def call_api(message, model, preset):
|
16 |
selected_server = random.choice(servers)
|
17 |
client = Client(selected_server)
|
18 |
|
19 |
try:
|
20 |
-
# Get API parameter names (replace with actual API parameter names from "View API")
|
21 |
result = client.predict(
|
22 |
message, # First input
|
23 |
model, # Second input (correct parameter name)
|
@@ -28,7 +28,7 @@ def call_api(message, model, preset):
|
|
28 |
except Exception as e:
|
29 |
return f"Error: {str(e)}"
|
30 |
|
31 |
-
# Custom CSS for clean UI
|
32 |
css = """
|
33 |
.gradio-container {
|
34 |
background-color: #f9f9f9;
|
@@ -66,7 +66,7 @@ css = """
|
|
66 |
border: none;
|
67 |
background: none;
|
68 |
cursor: pointer;
|
69 |
-
padding:
|
70 |
}
|
71 |
|
72 |
#send-button:hover {
|
@@ -78,31 +78,31 @@ css = """
|
|
78 |
}
|
79 |
"""
|
80 |
|
81 |
-
# Create Gradio interface
|
82 |
def create_interface():
|
83 |
with gr.Blocks(css=css) as demo:
|
84 |
gr.Markdown("## 💬 Chatbot")
|
85 |
|
86 |
-
# Chat display area
|
87 |
chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12)
|
88 |
|
89 |
-
# Input field with button inside
|
90 |
with gr.Row(elem_id="input-container"):
|
91 |
message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1, show_label=False)
|
92 |
send_btn = gr.Button("➤", elem_id="send-button")
|
93 |
|
94 |
-
# Settings section
|
95 |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
|
96 |
model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base")
|
97 |
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
|
98 |
dark_mode = gr.Checkbox(label="Enable Dark Mode", value=False)
|
99 |
|
100 |
-
# Button click event
|
101 |
send_btn.click(call_api, inputs=[message, model, preset], outputs=chatbox)
|
102 |
|
103 |
return demo
|
104 |
|
105 |
-
# Launch the interface
|
106 |
if __name__ == "__main__":
|
107 |
interface = create_interface()
|
108 |
interface.launch()
|
|
|
2 |
from gradio_client import Client
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# **List of available servers**
|
6 |
servers = [
|
7 |
"BICORP/GOGOGOGO",
|
8 |
"BICORP/server-2",
|
|
|
11 |
"BICORP/server-5"
|
12 |
]
|
13 |
|
14 |
+
# **Function to call the API with correct parameters**
|
15 |
def call_api(message, model, preset):
|
16 |
selected_server = random.choice(servers)
|
17 |
client = Client(selected_server)
|
18 |
|
19 |
try:
|
20 |
+
# **Get API parameter names (replace with actual API parameter names from "View API")**
|
21 |
result = client.predict(
|
22 |
message, # First input
|
23 |
model, # Second input (correct parameter name)
|
|
|
28 |
except Exception as e:
|
29 |
return f"Error: {str(e)}"
|
30 |
|
31 |
+
# **Custom CSS for clean UI**
|
32 |
css = """
|
33 |
.gradio-container {
|
34 |
background-color: #f9f9f9;
|
|
|
66 |
border: none;
|
67 |
background: none;
|
68 |
cursor: pointer;
|
69 |
+
padding: 10px;
|
70 |
}
|
71 |
|
72 |
#send-button:hover {
|
|
|
78 |
}
|
79 |
"""
|
80 |
|
81 |
+
# **Create Gradio interface**
|
82 |
def create_interface():
|
83 |
with gr.Blocks(css=css) as demo:
|
84 |
gr.Markdown("## 💬 Chatbot")
|
85 |
|
86 |
+
# **Chat display area**
|
87 |
chatbox = gr.Textbox(label="", interactive=False, elem_id="chatbox", lines=12)
|
88 |
|
89 |
+
# **Input field with button inside**
|
90 |
with gr.Row(elem_id="input-container"):
|
91 |
message = gr.Textbox(placeholder="Type a message...", elem_id="message-input", lines=1, show_label=False)
|
92 |
send_btn = gr.Button("➤", elem_id="send-button")
|
93 |
|
94 |
+
# **Settings section**
|
95 |
with gr.Accordion("⚙️ Settings", open=False, elem_id="settings-container"):
|
96 |
model = gr.Dropdown(choices=["Lake 1 Base"], label="Model", value="Lake 1 Base")
|
97 |
preset = gr.Dropdown(choices=["Fast", "Normal", "Quality", "Unreal Performance"], label="Preset", value="Fast")
|
98 |
dark_mode = gr.Checkbox(label="Enable Dark Mode", value=False)
|
99 |
|
100 |
+
# **Button click event**
|
101 |
send_btn.click(call_api, inputs=[message, model, preset], outputs=chatbox)
|
102 |
|
103 |
return demo
|
104 |
|
105 |
+
# **Launch the interface**
|
106 |
if __name__ == "__main__":
|
107 |
interface = create_interface()
|
108 |
interface.launch()
|