Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ custom_css = """
|
|
21 |
animation: gradient-animation 15s ease infinite;
|
22 |
}
|
23 |
|
24 |
-
/* Style for
|
25 |
.main-container {
|
26 |
background-color: rgba(255, 255, 255, 0.95);
|
27 |
backdrop-filter: blur(10px);
|
@@ -29,72 +29,53 @@ custom_css = """
|
|
29 |
padding: 20px;
|
30 |
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
31 |
border: 1px solid rgba(255, 255, 255, 0.18);
|
|
|
32 |
}
|
33 |
|
34 |
.dark .main-container {
|
35 |
background-color: rgba(30, 30, 30, 0.95);
|
36 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
37 |
}
|
38 |
-
|
39 |
-
/* Sidebar styling */
|
40 |
-
.sidebar {
|
41 |
-
background-color: rgba(255, 255, 255, 0.9);
|
42 |
-
backdrop-filter: blur(10px);
|
43 |
-
border-radius: 15px;
|
44 |
-
padding: 20px;
|
45 |
-
margin: 10px;
|
46 |
-
}
|
47 |
-
|
48 |
-
.dark .sidebar {
|
49 |
-
background-color: rgba(40, 40, 40, 0.9);
|
50 |
-
}
|
51 |
-
|
52 |
-
/* Chat interface styling */
|
53 |
-
.chat-container {
|
54 |
-
height: 600px;
|
55 |
-
}
|
56 |
"""
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
)
|
65 |
|
66 |
with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
|
67 |
-
# State to track login status
|
68 |
-
is_logged_in = gr.State(False)
|
69 |
-
|
70 |
with gr.Row():
|
|
|
71 |
with gr.Column(scale=1):
|
72 |
-
with gr.Group(elem_classes="
|
73 |
gr.Markdown("# ๐ Inference Provider")
|
74 |
gr.Markdown(
|
75 |
"This Space showcases OpenAI GPT-OSS models, served by the Cerebras API. "
|
76 |
"Sign in with your Hugging Face account to use this API."
|
77 |
)
|
78 |
|
79 |
-
# Model selection
|
80 |
model_dropdown = gr.Dropdown(
|
81 |
choices=[
|
82 |
"openai/gpt-oss-120b",
|
83 |
"openai/gpt-oss-20b"
|
84 |
],
|
85 |
value="openai/gpt-oss-120b",
|
86 |
-
label="Select Model",
|
87 |
info="Choose between different model sizes"
|
88 |
)
|
89 |
|
90 |
# Login button
|
91 |
login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
92 |
|
93 |
-
#
|
94 |
-
|
95 |
|
96 |
# Additional options
|
97 |
with gr.Accordion("โ๏ธ Advanced Options", open=False):
|
|
|
98 |
temperature = gr.Slider(
|
99 |
minimum=0,
|
100 |
maximum=2,
|
@@ -109,87 +90,43 @@ with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as d
|
|
109 |
step=1,
|
110 |
label="Max Tokens"
|
111 |
)
|
112 |
-
|
113 |
-
# Load model button
|
114 |
-
load_button = gr.Button("๐ Load Selected Model", variant="primary", size="lg")
|
115 |
|
|
|
116 |
with gr.Column(scale=3):
|
117 |
with gr.Group(elem_classes="main-container"):
|
118 |
gr.Markdown("## ๐ฌ Chat Interface")
|
119 |
|
120 |
-
#
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
# Handle login status
|
129 |
-
def update_login_status(profile):
|
130 |
-
if profile:
|
131 |
-
return gr.update(value="โ
Logged in", visible=True), True
|
132 |
-
return gr.update(value="โ Not logged in", visible=True), False
|
133 |
-
|
134 |
-
# Load the selected model
|
135 |
-
def load_selected_model(model_name, logged_in):
|
136 |
-
if not logged_in:
|
137 |
-
gr.Warning("Please sign in first to use the models!")
|
138 |
-
return
|
139 |
-
|
140 |
-
gr.Info(f"Loading {model_name}... This may take a moment.")
|
141 |
-
|
142 |
-
# Here you would implement the actual model loading
|
143 |
-
# For now, we'll update the chat interface
|
144 |
-
try:
|
145 |
-
# Load the model-specific interface
|
146 |
-
loaded_interface = gr.load(
|
147 |
-
f"models/{model_name}",
|
148 |
-
accept_token=True,
|
149 |
-
provider="fireworks-ai"
|
150 |
-
)
|
151 |
-
gr.Success(f"Successfully loaded {model_name}!")
|
152 |
-
return loaded_interface
|
153 |
-
except Exception as e:
|
154 |
-
gr.Error(f"Failed to load model: {str(e)}")
|
155 |
-
return None
|
156 |
|
157 |
-
#
|
158 |
-
|
159 |
-
fn=
|
160 |
-
inputs=[
|
161 |
-
outputs=[
|
|
|
|
|
|
|
|
|
162 |
)
|
163 |
|
164 |
-
#
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
)
|
170 |
|
171 |
-
# Alternative approach: Direct loading with model selection
|
172 |
-
# Uncomment this if you want to use the original approach with modifications
|
173 |
-
"""
|
174 |
-
with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
|
175 |
-
with gr.Row():
|
176 |
-
with gr.Column(scale=1):
|
177 |
-
with gr.Group(elem_classes="sidebar"):
|
178 |
-
gr.Markdown("# ๐ Inference Provider")
|
179 |
-
gr.Markdown("This Space showcases OpenAI GPT-OSS models. Sign in to use.")
|
180 |
-
|
181 |
-
model_choice = gr.Radio(
|
182 |
-
choices=["openai/gpt-oss-120b", "openai/gpt-oss-20b"],
|
183 |
-
value="openai/gpt-oss-120b",
|
184 |
-
label="Select Model"
|
185 |
-
)
|
186 |
-
|
187 |
-
button = gr.LoginButton("Sign in")
|
188 |
-
|
189 |
-
with gr.Column(scale=3):
|
190 |
-
with gr.Group(elem_classes="main-container"):
|
191 |
-
# Default to 120b model
|
192 |
-
gr.load("models/openai/gpt-oss-120b", accept_token=button, provider="fireworks-ai")
|
193 |
-
"""
|
194 |
-
|
195 |
demo.launch()
|
|
|
21 |
animation: gradient-animation 15s ease infinite;
|
22 |
}
|
23 |
|
24 |
+
/* Style for content areas */
|
25 |
.main-container {
|
26 |
background-color: rgba(255, 255, 255, 0.95);
|
27 |
backdrop-filter: blur(10px);
|
|
|
29 |
padding: 20px;
|
30 |
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
31 |
border: 1px solid rgba(255, 255, 255, 0.18);
|
32 |
+
margin: 10px;
|
33 |
}
|
34 |
|
35 |
.dark .main-container {
|
36 |
background-color: rgba(30, 30, 30, 0.95);
|
37 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
38 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
"""
|
40 |
|
41 |
+
# State variable to track current model
|
42 |
+
current_model = gr.State("openai/gpt-oss-120b")
|
43 |
+
|
44 |
+
def switch_model(model_choice):
|
45 |
+
"""Function to switch between models"""
|
46 |
+
return gr.update(visible=False), gr.update(visible=True), model_choice
|
|
|
47 |
|
48 |
with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
|
|
|
|
|
|
|
49 |
with gr.Row():
|
50 |
+
# Sidebar
|
51 |
with gr.Column(scale=1):
|
52 |
+
with gr.Group(elem_classes="main-container"):
|
53 |
gr.Markdown("# ๐ Inference Provider")
|
54 |
gr.Markdown(
|
55 |
"This Space showcases OpenAI GPT-OSS models, served by the Cerebras API. "
|
56 |
"Sign in with your Hugging Face account to use this API."
|
57 |
)
|
58 |
|
59 |
+
# Model selection
|
60 |
model_dropdown = gr.Dropdown(
|
61 |
choices=[
|
62 |
"openai/gpt-oss-120b",
|
63 |
"openai/gpt-oss-20b"
|
64 |
],
|
65 |
value="openai/gpt-oss-120b",
|
66 |
+
label="๐ Select Model",
|
67 |
info="Choose between different model sizes"
|
68 |
)
|
69 |
|
70 |
# Login button
|
71 |
login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
72 |
|
73 |
+
# Reload button to apply model change
|
74 |
+
reload_btn = gr.Button("๐ Apply Model Change", variant="primary", size="lg")
|
75 |
|
76 |
# Additional options
|
77 |
with gr.Accordion("โ๏ธ Advanced Options", open=False):
|
78 |
+
gr.Markdown("*These options will be available after model implementation*")
|
79 |
temperature = gr.Slider(
|
80 |
minimum=0,
|
81 |
maximum=2,
|
|
|
90 |
step=1,
|
91 |
label="Max Tokens"
|
92 |
)
|
|
|
|
|
|
|
93 |
|
94 |
+
# Main chat area
|
95 |
with gr.Column(scale=3):
|
96 |
with gr.Group(elem_classes="main-container"):
|
97 |
gr.Markdown("## ๐ฌ Chat Interface")
|
98 |
|
99 |
+
# Container for model interfaces
|
100 |
+
with gr.Column(visible=True) as model_120b_container:
|
101 |
+
gr.Markdown("### Model: openai/gpt-oss-120b")
|
102 |
+
gr.load("models/openai/gpt-oss-120b", accept_token=login_button, provider="fireworks-ai")
|
103 |
+
|
104 |
+
with gr.Column(visible=False) as model_20b_container:
|
105 |
+
gr.Markdown("### Model: openai/gpt-oss-20b")
|
106 |
+
gr.load("models/openai/gpt-oss-20b", accept_token=login_button, provider="fireworks-ai")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
# Handle model switching
|
109 |
+
reload_btn.click(
|
110 |
+
fn=switch_model,
|
111 |
+
inputs=[model_dropdown],
|
112 |
+
outputs=[model_120b_container, model_20b_container, current_model]
|
113 |
+
).then(
|
114 |
+
fn=lambda: gr.Info("Model switched successfully!"),
|
115 |
+
inputs=[],
|
116 |
+
outputs=[]
|
117 |
)
|
118 |
|
119 |
+
# Update visibility based on dropdown selection
|
120 |
+
def update_visibility(model_choice):
|
121 |
+
if model_choice == "openai/gpt-oss-120b":
|
122 |
+
return gr.update(visible=True), gr.update(visible=False)
|
123 |
+
else:
|
124 |
+
return gr.update(visible=False), gr.update(visible=True)
|
125 |
+
|
126 |
+
model_dropdown.change(
|
127 |
+
fn=update_visibility,
|
128 |
+
inputs=[model_dropdown],
|
129 |
+
outputs=[model_120b_container, model_20b_container]
|
130 |
)
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
demo.launch()
|