openfree commited on
Commit
0a94c2d
ยท
verified ยท
1 Parent(s): df97c7f

Create backup.py

Browse files
Files changed (1) hide show
  1. backup.py +128 -0
backup.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ @keyframes gradient-animation {
12
+ 0% { background-position: 0% 50%; }
13
+ 50% { background-position: 100% 50%; }
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=gr.themes.Soft, css=custom_css) as demo:
45
+ with gr.Row():
46
+ # Sidebar
47
+ with gr.Column(scale=1):
48
+ with gr.Group(elem_classes="main-container"):
49
+ gr.Markdown("# ๐Ÿš€ Inference Provider")
50
+ gr.Markdown(
51
+ "This Space showcases OpenAI GPT-OSS models, served by the Cerebras API. "
52
+ "Sign in with your Hugging Face account to use this API."
53
+ )
54
+
55
+ # Model selection
56
+ model_dropdown = gr.Dropdown(
57
+ choices=[
58
+ "openai/gpt-oss-120b",
59
+ "openai/gpt-oss-20b"
60
+ ],
61
+ value="openai/gpt-oss-120b",
62
+ label="๐Ÿ“Š Select Model",
63
+ info="Choose between different model sizes"
64
+ )
65
+
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*")
75
+ temperature = gr.Slider(
76
+ minimum=0,
77
+ maximum=2,
78
+ value=0.7,
79
+ step=0.1,
80
+ label="Temperature"
81
+ )
82
+ max_tokens = gr.Slider(
83
+ minimum=1,
84
+ maximum=4096,
85
+ value=512,
86
+ step=1,
87
+ label="Max Tokens"
88
+ )
89
+
90
+ # Main chat area
91
+ with gr.Column(scale=3):
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()