Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
# Custom CSS for gradient background and styling
|
4 |
custom_css = """
|
5 |
.gradio-container {
|
6 |
-
background: linear-gradient(135deg, #
|
7 |
background-size: 400% 400%;
|
8 |
animation: gradient-animation 15s ease infinite;
|
9 |
min-height: 100vh;
|
@@ -14,34 +14,34 @@ custom_css = """
|
|
14 |
100% { background-position: 0% 50%; }
|
15 |
}
|
16 |
.dark .gradio-container {
|
17 |
-
background: linear-gradient(135deg, #
|
18 |
background-size: 400% 400%;
|
19 |
animation: gradient-animation 15s ease infinite;
|
20 |
}
|
21 |
/* Style for content areas */
|
22 |
.main-container {
|
23 |
-
background-color: rgba(255, 255, 255, 0.
|
24 |
backdrop-filter: blur(10px);
|
25 |
border-radius: 20px;
|
26 |
padding: 20px;
|
27 |
-
box-shadow: 0
|
28 |
-
border: 1px solid rgba(255, 255, 255, 0.
|
29 |
margin: 10px;
|
30 |
}
|
31 |
.dark .main-container {
|
32 |
-
background-color: rgba(
|
33 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
34 |
}
|
35 |
"""
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
return f"Response from {model_choice}: {message}"
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
with gr.Row():
|
46 |
# Sidebar
|
47 |
with gr.Column(scale=1):
|
@@ -66,6 +66,9 @@ with gr.Blocks(fill_height=True, theme="soft", css=custom_css) as demo:
|
|
66 |
# Login button
|
67 |
login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
68 |
|
|
|
|
|
|
|
69 |
# Additional options
|
70 |
with gr.Accordion("⚙️ Advanced Options", open=False):
|
71 |
gr.Markdown("*These options will be available after model implementation*")
|
@@ -89,77 +92,37 @@ with gr.Blocks(fill_height=True, theme="soft", css=custom_css) as demo:
|
|
89 |
with gr.Group(elem_classes="main-container"):
|
90 |
gr.Markdown("## 💬 Chat Interface")
|
91 |
|
92 |
-
#
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
chatbot = gr.Chatbot(
|
97 |
-
height=400,
|
98 |
-
show_label=False,
|
99 |
-
elem_classes="main-container"
|
100 |
-
)
|
101 |
-
|
102 |
-
with gr.Row():
|
103 |
-
msg = gr.Textbox(
|
104 |
-
placeholder="Type your message here...",
|
105 |
-
show_label=False,
|
106 |
-
scale=9
|
107 |
-
)
|
108 |
-
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
109 |
|
110 |
-
|
|
|
|
|
111 |
|
112 |
-
#
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
model_dropdown.change(
|
117 |
-
fn=update_model_display,
|
118 |
inputs=[model_dropdown],
|
119 |
-
outputs=[
|
120 |
-
)
|
121 |
-
|
122 |
-
# Chat functionality
|
123 |
-
def respond(message, chat_history, model):
|
124 |
-
if not message:
|
125 |
-
return "", chat_history
|
126 |
-
|
127 |
-
# Add user message to history
|
128 |
-
chat_history = chat_history + [[message, None]]
|
129 |
-
|
130 |
-
# Generate bot response (placeholder - replace with actual model call)
|
131 |
-
bot_response = f"[{model.split('/')[-1]}]: This is a placeholder response. In production, this would connect to the {model} via Fireworks AI API."
|
132 |
-
|
133 |
-
# Update the last message with bot response
|
134 |
-
chat_history[-1][1] = bot_response
|
135 |
-
|
136 |
-
return "", chat_history
|
137 |
-
|
138 |
-
# Submit message on button click or enter
|
139 |
-
submit_btn.click(
|
140 |
-
fn=respond,
|
141 |
-
inputs=[msg, chatbot, current_model],
|
142 |
-
outputs=[msg, chatbot]
|
143 |
-
)
|
144 |
-
|
145 |
-
msg.submit(
|
146 |
-
fn=respond,
|
147 |
-
inputs=[msg, chatbot, current_model],
|
148 |
-
outputs=[msg, chatbot]
|
149 |
-
)
|
150 |
-
|
151 |
-
# Clear chat
|
152 |
-
clear_btn.click(
|
153 |
-
fn=lambda: (None, ""),
|
154 |
inputs=[],
|
155 |
-
outputs=[
|
156 |
)
|
157 |
|
158 |
-
#
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
)
|
164 |
|
165 |
demo.launch()
|
|
|
3 |
# Custom CSS for gradient background and styling
|
4 |
custom_css = """
|
5 |
.gradio-container {
|
6 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
|
7 |
background-size: 400% 400%;
|
8 |
animation: gradient-animation 15s ease infinite;
|
9 |
min-height: 100vh;
|
|
|
14 |
100% { background-position: 0% 50%; }
|
15 |
}
|
16 |
.dark .gradio-container {
|
17 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 25%, #0f3460 50%, #533483 75%, #e94560 100%);
|
18 |
background-size: 400% 400%;
|
19 |
animation: gradient-animation 15s ease infinite;
|
20 |
}
|
21 |
/* Style for content areas */
|
22 |
.main-container {
|
23 |
+
background-color: rgba(255, 255, 255, 0.95);
|
24 |
backdrop-filter: blur(10px);
|
25 |
border-radius: 20px;
|
26 |
padding: 20px;
|
27 |
+
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
28 |
+
border: 1px solid rgba(255, 255, 255, 0.18);
|
29 |
margin: 10px;
|
30 |
}
|
31 |
.dark .main-container {
|
32 |
+
background-color: rgba(30, 30, 30, 0.95);
|
33 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
34 |
}
|
35 |
"""
|
36 |
|
37 |
+
# State variable to track current model
|
38 |
+
current_model = gr.State("openai/gpt-oss-120b")
|
|
|
39 |
|
40 |
+
def switch_model(model_choice):
|
41 |
+
"""Function to switch between models"""
|
42 |
+
return gr.update(visible=False), gr.update(visible=True), model_choice
|
43 |
+
|
44 |
+
with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
|
45 |
with gr.Row():
|
46 |
# Sidebar
|
47 |
with gr.Column(scale=1):
|
|
|
66 |
# Login button
|
67 |
login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
68 |
|
69 |
+
# Reload button to apply model change
|
70 |
+
reload_btn = gr.Button("🔄 Apply Model Change", variant="primary", size="lg")
|
71 |
+
|
72 |
# Additional options
|
73 |
with gr.Accordion("⚙️ Advanced Options", open=False):
|
74 |
gr.Markdown("*These options will be available after model implementation*")
|
|
|
92 |
with gr.Group(elem_classes="main-container"):
|
93 |
gr.Markdown("## 💬 Chat Interface")
|
94 |
|
95 |
+
# Container for model interfaces
|
96 |
+
with gr.Column(visible=True) as model_120b_container:
|
97 |
+
gr.Markdown("### Model: openai/gpt-oss-120b")
|
98 |
+
gr.load("models/openai/gpt-oss-120b", accept_token=login_button, provider="fireworks-ai")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
+
with gr.Column(visible=False) as model_20b_container:
|
101 |
+
gr.Markdown("### Model: openai/gpt-oss-20b")
|
102 |
+
gr.load("models/openai/gpt-oss-20b", accept_token=login_button, provider="fireworks-ai")
|
103 |
|
104 |
+
# Handle model switching
|
105 |
+
reload_btn.click(
|
106 |
+
fn=switch_model,
|
|
|
|
|
|
|
107 |
inputs=[model_dropdown],
|
108 |
+
outputs=[model_120b_container, model_20b_container, current_model]
|
109 |
+
).then(
|
110 |
+
fn=lambda: gr.Info("Model switched successfully!"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
inputs=[],
|
112 |
+
outputs=[]
|
113 |
)
|
114 |
|
115 |
+
# Update visibility based on dropdown selection
|
116 |
+
def update_visibility(model_choice):
|
117 |
+
if model_choice == "openai/gpt-oss-120b":
|
118 |
+
return gr.update(visible=True), gr.update(visible=False)
|
119 |
+
else:
|
120 |
+
return gr.update(visible=False), gr.update(visible=True)
|
121 |
+
|
122 |
+
model_dropdown.change(
|
123 |
+
fn=update_visibility,
|
124 |
+
inputs=[model_dropdown],
|
125 |
+
outputs=[model_120b_container, model_20b_container]
|
126 |
)
|
127 |
|
128 |
demo.launch()
|