Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 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;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
@keyframes gradient-animation {
|
| 13 |
+
0% { background-position: 0% 50%; }
|
| 14 |
+
50% { background-position: 100% 50%; }
|
| 15 |
+
100% { background-position: 0% 50%; }
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
.dark .gradio-container {
|
| 19 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 25%, #0f3460 50%, #533483 75%, #e94560 100%);
|
| 20 |
+
background-size: 400% 400%;
|
| 21 |
+
animation: gradient-animation 15s ease infinite;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* Style for the main content area */
|
| 25 |
+
.main-container {
|
| 26 |
+
background-color: rgba(255, 255, 255, 0.95);
|
| 27 |
+
backdrop-filter: blur(10px);
|
| 28 |
+
border-radius: 20px;
|
| 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 |
+
|
| 53 |
+
def load_model(model_name, signed_in):
|
| 54 |
+
"""Function to load different models based on selection"""
|
| 55 |
+
if not signed_in:
|
| 56 |
+
return gr.Info("Please sign in to use the models")
|
| 57 |
+
|
| 58 |
+
# Here you would implement the actual model loading logic
|
| 59 |
+
# For now, we'll return a placeholder
|
| 60 |
+
return f"Model {model_name} loaded successfully!"
|
| 61 |
+
|
| 62 |
+
with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
|
| 63 |
+
with gr.Row():
|
| 64 |
+
with gr.Column(scale=1):
|
| 65 |
+
with gr.Group(elem_classes="sidebar"):
|
| 66 |
+
gr.Markdown("# 🚀 Inference Provider")
|
| 67 |
+
gr.Markdown(
|
| 68 |
+
"This Space showcases OpenAI GPT-OSS models, served by the Cerebras API. "
|
| 69 |
+
"Sign in with your Hugging Face account to use this API."
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# Model selection dropdown
|
| 73 |
+
model_dropdown = gr.Dropdown(
|
| 74 |
+
choices=[
|
| 75 |
+
"openai/gpt-oss-120b",
|
| 76 |
+
"openai/gpt-oss-20b"
|
| 77 |
+
],
|
| 78 |
+
value="openai/gpt-oss-120b",
|
| 79 |
+
label="Select Model",
|
| 80 |
+
info="Choose between different model sizes"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Login button
|
| 84 |
+
button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
| 85 |
+
|
| 86 |
+
# Additional options
|
| 87 |
+
with gr.Accordion("⚙️ Advanced Options", open=False):
|
| 88 |
+
temperature = gr.Slider(
|
| 89 |
+
minimum=0,
|
| 90 |
+
maximum=2,
|
| 91 |
+
value=0.7,
|
| 92 |
+
step=0.1,
|
| 93 |
+
label="Temperature"
|
| 94 |
+
)
|
| 95 |
+
max_tokens = gr.Slider(
|
| 96 |
+
minimum=1,
|
| 97 |
+
maximum=4096,
|
| 98 |
+
value=512,
|
| 99 |
+
step=1,
|
| 100 |
+
label="Max Tokens"
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
with gr.Column(scale=3):
|
| 104 |
+
with gr.Group(elem_classes="main-container"):
|
| 105 |
+
# Dynamic model loading based on selection
|
| 106 |
+
@gr.render(inputs=[model_dropdown, button])
|
| 107 |
+
def render_model_interface(selected_model, login_status):
|
| 108 |
+
if selected_model == "openai/gpt-oss-120b":
|
| 109 |
+
gr.load(
|
| 110 |
+
"models/openai/gpt-oss-120b",
|
| 111 |
+
accept_token=login_status,
|
| 112 |
+
provider="fireworks-ai"
|
| 113 |
+
)
|
| 114 |
+
elif selected_model == "openai/gpt-oss-20b":
|
| 115 |
+
gr.load(
|
| 116 |
+
"models/openai/gpt-oss-20b",
|
| 117 |
+
accept_token=login_status,
|
| 118 |
+
provider="fireworks-ai"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
demo.launch()
|