Chris Addis commited on
Commit
57f4443
·
1 Parent(s): 46c08d9
Files changed (1) hide show
  1. app.py +53 -59
app.py CHANGED
@@ -126,82 +126,76 @@ def create_demo():
126
  show_share_button=False, show_fullscreen_button=False,
127
  container=False, elem_id="nml-logo")
128
 
129
- # Store model choices and state
130
- show_all_models_state = gr.State(False)
131
-
132
- # Define preferred and additional models directly in the function
133
- preferred_models = [
134
- ("Gemini 2.0 Flash (cheap)", "google/gemini-2.0-flash-001"),
135
- ("GPT-4.1 Mini", "gpt-4.1-mini"),
136
- ("GPT-4.1 (Recommended)", "gpt-4.1"),
137
- ("Claude 3.7 Sonnet", "anthropic/claude-3.7-sonnet"),
138
- ("Gemini 2.5 Pro", "google/gemini-2.5-pro-preview-03-25"),
139
- ("Gemini 2.5 Flash Thinking (Recommended)", "google/gemini-2.5-flash-preview:thinking")
140
- ]
141
-
142
- additional_models = [
143
- ("GPT-4.1 Nano", "gpt-4.1-nano"),
144
- ("ChatGPT Latest", "openai/chatgpt-4o-latest"),
145
- ("Llama 4 Maverick", "meta-llama/llama-4-maverick")
146
- ]
147
-
148
- # Calculate all models once
149
- all_models_list = preferred_models + additional_models
150
-
151
- # Default model value
152
- default_model = "google/gemini-2.0-flash-001"
153
-
154
  with gr.Row():
155
  # Left column: Controls and uploads
156
  with gr.Column(scale=1):
157
 
158
  ##########################################################################
159
- # Function to check authorization
160
- def check_authorization(profile: gr.OAuthProfile | None):
161
- if profile is None:
162
- return True
163
-
164
- is_authorized = profile.username not in AUTHORIZED_USER_IDS
165
- return is_authorized
166
-
167
- #new bit with authroisation
168
- # define it false to begin with
169
- #auth_state = gr.State(False)
170
-
171
- #demo.load(check_authorization, inputs=None, outputs=[auth_state])
172
 
173
- with gr.Group(visible=False) as unauthenticated_ui:
174
- # free version - yeah baby
175
- login_button = gr.LoginButton()
176
 
177
- # Define preferred and additional models directly in the function
178
- preferred_models = [
179
- ("Llama 4 Maverick (free)", "meta-llama/llama-4-maverick:free")
180
- ]
181
-
182
- all_models_list = preferred_models
183
-
184
- # Default model value
185
- default_model = "meta-llama/llama-4-maverick:free"#preferred_models[0][1] # get free model
186
- demo.load(
187
- fn=check_authorization,
188
- inputs=None,
189
- outputs=[unauthenticated_ui]
190
- )
191
- ################################## normal stuff below
192
  upload_button = gr.UploadButton(
193
  "Click to Upload Images",
194
  file_types=["image"],
195
  file_count="multiple"
196
  )
197
-
198
- # Model dropdown
199
  model_choice = gr.Dropdown(
200
  choices=preferred_models,
201
  label="Select Model",
202
- value=default_model
203
  )
 
 
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  length_choice = gr.Radio(
206
  choices=["short", "medium", "long"],
207
  label="Response Length",
 
126
  show_share_button=False, show_fullscreen_button=False,
127
  container=False, elem_id="nml-logo")
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  with gr.Row():
130
  # Left column: Controls and uploads
131
  with gr.Column(scale=1):
132
 
133
  ##########################################################################
134
+ # Define preferred and additional models directly in the function
135
+ preferred_models = [
136
+ ("Llama 4 Maverick (free)", "meta-llama/llama-4-maverick:free")
137
+ ]
 
 
 
 
 
 
 
 
 
138
 
139
+ login_button = gr.LoginButton(visible=False)
 
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  upload_button = gr.UploadButton(
142
  "Click to Upload Images",
143
  file_types=["image"],
144
  file_count="multiple"
145
  )
146
+
 
147
  model_choice = gr.Dropdown(
148
  choices=preferred_models,
149
  label="Select Model",
150
+ value="meta-llama/llama-4-maverick:free"
151
  )
152
+
153
+ default_model = gr.state()
154
 
155
+ # Function to check authorization
156
+ def check_authorization(profile: gr.OAuthProfile | None):
157
+ if profile is None:
158
+ return False
159
+
160
+ is_authorized = profile.username in AUTHORIZED_USER_IDS
161
+ if is_authorized:
162
+ # Define preferred and additional models directly in the function
163
+ preferred_models_auth = [
164
+ ("Gemini 2.0 Flash (cheap)", "google/gemini-2.0-flash-001"),
165
+ ("GPT-4.1 Mini", "gpt-4.1-mini"),
166
+ ("GPT-4.1 (Recommended)", "gpt-4.1"),
167
+ ("Claude 3.7 Sonnet", "anthropic/claude-3.7-sonnet"),
168
+ ("Gemini 2.5 Pro", "google/gemini-2.5-pro-preview-03-25"),
169
+ ("Gemini 2.5 Flash Thinking (Recommended)", "google/gemini-2.5-flash-preview:thinking")
170
+ ]
171
+
172
+ additional_models = [
173
+ ("GPT-4.1 Nano", "gpt-4.1-nano"),
174
+ ("ChatGPT Latest", "openai/chatgpt-4o-latest"),
175
+ ("Llama 4 Maverick", "meta-llama/llama-4-maverick")
176
+ ]
177
+
178
+ # Calculate all models once
179
+ all_models_list = preferred_models + additional_models
180
+
181
+ # Default model value
182
+ default_model = "google/gemini-2.0-flash-001"
183
+
184
+ return gr.Dropdown(choices=preferred_models, label="Select Model",value=default_model),False,default_model
185
+ else:
186
+ all_models_list = preferred_models
187
+
188
+ # Default model value
189
+ default_model = "meta-llama/llama-4-maverick:free"#preferred_models[0][1] # get free model
190
+ return gr.Dropdown(choices=preferred_models, label="Select Model",value=default_model),True,default_model
191
+
192
+ demo.load(
193
+ fn=check_authorization,
194
+ inputs=None,
195
+ outputs=[model_choice,login_button,default_model]
196
+ )
197
+ ################################## normal stuff below
198
+
199
  length_choice = gr.Radio(
200
  choices=["short", "medium", "long"],
201
  label="Response Length",