File size: 6,794 Bytes
9b2f298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d0296f
 
 
 
 
9b2f298
 
7d0296f
 
 
 
 
 
 
9b2f298
 
7d0296f
 
 
9b2f298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d0296f
 
 
 
9b2f298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d0296f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b2f298
 
 
7d0296f
 
 
9b2f298
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import gradio as gr

# Custom CSS for gradient background and styling
custom_css = """
.gradio-container {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
    background-size: 400% 400%;
    animation: gradient-animation 15s ease infinite;
    min-height: 100vh;
}

@keyframes gradient-animation {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.dark .gradio-container {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 25%, #0f3460 50%, #533483 75%, #e94560 100%);
    background-size: 400% 400%;
    animation: gradient-animation 15s ease infinite;
}

/* Style for the main content area */
.main-container {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.dark .main-container {
    background-color: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Sidebar styling */
.sidebar {
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 20px;
    margin: 10px;
}

.dark .sidebar {
    background-color: rgba(40, 40, 40, 0.9);
}

/* Chat interface styling */
.chat-container {
    height: 600px;
}
"""

def create_chat_interface(model_name):
    """Create a chat interface for the selected model"""
    # This creates the actual chat interface
    return gr.load(
        f"models/{model_name}",
        provider="fireworks-ai"
    )

with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
    # State to track login status
    is_logged_in = gr.State(False)
    
    with gr.Row():
        with gr.Column(scale=1):
            with gr.Group(elem_classes="sidebar"):
                gr.Markdown("# ๐Ÿš€ Inference Provider")
                gr.Markdown(
                    "This Space showcases OpenAI GPT-OSS models, served by the Cerebras API. "
                    "Sign in with your Hugging Face account to use this API."
                )
                
                # Model selection dropdown
                model_dropdown = gr.Dropdown(
                    choices=[
                        "openai/gpt-oss-120b",
                        "openai/gpt-oss-20b"
                    ],
                    value="openai/gpt-oss-120b",
                    label="Select Model",
                    info="Choose between different model sizes"
                )
                
                # Login button
                login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
                
                # Status display
                status_text = gr.Markdown("โŒ Not logged in", visible=True)
                
                # Additional options
                with gr.Accordion("โš™๏ธ Advanced Options", open=False):
                    temperature = gr.Slider(
                        minimum=0,
                        maximum=2,
                        value=0.7,
                        step=0.1,
                        label="Temperature"
                    )
                    max_tokens = gr.Slider(
                        minimum=1,
                        maximum=4096,
                        value=512,
                        step=1,
                        label="Max Tokens"
                    )
                    
                # Load model button
                load_button = gr.Button("๐Ÿ”„ Load Selected Model", variant="primary", size="lg")
        
        with gr.Column(scale=3):
            with gr.Group(elem_classes="main-container"):
                gr.Markdown("## ๐Ÿ’ฌ Chat Interface")
                
                # Chat interface placeholder
                chat_interface = gr.ChatInterface(
                    fn=lambda message, history: "Please sign in and load a model to start chatting.",
                    examples=["Hello! How are you?", "What can you help me with?", "Tell me a joke"],
                    retry_btn=None,
                    undo_btn="Delete Previous",
                    clear_btn="Clear",
                    elem_classes="chat-container"
                )
    
    # Handle login status
    def update_login_status(profile):
        if profile:
            return gr.update(value="โœ… Logged in", visible=True), True
        return gr.update(value="โŒ Not logged in", visible=True), False
    
    # Load the selected model
    def load_selected_model(model_name, logged_in):
        if not logged_in:
            gr.Warning("Please sign in first to use the models!")
            return
        
        gr.Info(f"Loading {model_name}... This may take a moment.")
        
        # Here you would implement the actual model loading
        # For now, we'll update the chat interface
        try:
            # Load the model-specific interface
            loaded_interface = gr.load(
                f"models/{model_name}",
                accept_token=True,
                provider="fireworks-ai"
            )
            gr.Success(f"Successfully loaded {model_name}!")
            return loaded_interface
        except Exception as e:
            gr.Error(f"Failed to load model: {str(e)}")
            return None
    
    # Connect the login button to status update
    login_button.click(
        fn=update_login_status,
        inputs=[login_button],
        outputs=[status_text, is_logged_in]
    )
    
    # Connect the load button
    load_button.click(
        fn=load_selected_model,
        inputs=[model_dropdown, is_logged_in],
        outputs=[]
    )

# Alternative approach: Direct loading with model selection
# Uncomment this if you want to use the original approach with modifications
"""
with gr.Blocks(fill_height=True, theme="Nymbo/Nymbo_Theme", css=custom_css) as demo:
    with gr.Row():
        with gr.Column(scale=1):
            with gr.Group(elem_classes="sidebar"):
                gr.Markdown("# ๐Ÿš€ Inference Provider")
                gr.Markdown("This Space showcases OpenAI GPT-OSS models. Sign in to use.")
                
                model_choice = gr.Radio(
                    choices=["openai/gpt-oss-120b", "openai/gpt-oss-20b"],
                    value="openai/gpt-oss-120b",
                    label="Select Model"
                )
                
                button = gr.LoginButton("Sign in")
        
        with gr.Column(scale=3):
            with gr.Group(elem_classes="main-container"):
                # Default to 120b model
                gr.load("models/openai/gpt-oss-120b", accept_token=button, provider="fireworks-ai")
"""

demo.launch()