Chris Addis commited on
Commit
7e8ff28
·
1 Parent(s): 85c57b7
Files changed (1) hide show
  1. app.py +37 -38
app.py CHANGED
@@ -22,7 +22,6 @@ OR = OpenRouterAPI()
22
  authorized_users_str = os.environ.get("AUTHORIZED_USER_IDS", "")
23
  AUTHORIZED_USER_IDS = set(authorized_users_str.split(',') if authorized_users_str and authorized_users_str.strip() else [])
24
 
25
-
26
  # Define model pricing information (approximate costs per 100 image API calls)
27
  MODEL_PRICING = {
28
  "google/gemini-2.0-flash-001": "$0.03",
@@ -81,6 +80,43 @@ def get_base_filename(filepath):
81
  filename = os.path.splitext(basename)[0]
82
  return filename
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  # Define the Gradio interface
85
  def create_demo():
86
  custom_css = """
@@ -154,43 +190,6 @@ def create_demo():
154
  label="Select Model",
155
  value="meta-llama/llama-4-maverick:free"
156
  )
157
-
158
- # Function to check authorization
159
- def check_authorization(profile: gr.OAuthProfile | None):
160
-
161
- is_authorized = profile.username in AUTHORIZED_USER_IDS
162
- if is_authorized:
163
- # Define preferred and additional models directly in the function
164
- preferred_models_auth = [
165
- ("Gemini 2.0 Flash (cheap)", "google/gemini-2.0-flash-001"),
166
- ("GPT-4.1 Mini", "gpt-4.1-mini"),
167
- ("GPT-4.1 (Recommended)", "gpt-4.1"),
168
- ("Claude 3.7 Sonnet", "anthropic/claude-3.7-sonnet"),
169
- ("Gemini 2.5 Pro", "google/gemini-2.5-pro-preview-03-25"),
170
- ("Gemini 2.5 Flash Thinking (Recommended)","google/gemini-2.5-flash-preview")
171
- ]
172
-
173
- additional_models = [
174
- ("GPT-4.1 Nano", "gpt-4.1-nano"),
175
- ("ChatGPT Latest", "openai/chatgpt-4o-latest"),
176
- ("Llama 4 Maverick", "meta-llama/llama-4-maverick")
177
- ]
178
-
179
- # Calculate all models once
180
- all_models_list = preferred_models + additional_models
181
-
182
- text = f"""**Current Model**: Gemini 2.0 Flash (cheap)
183
- **Estimated cost per 100 Images**: {MODEL_PRICING["google/gemini-2.0-flash-001"]}"""
184
-
185
- return gr.Update(choices=preferred_models_auth, label="Select Model",value="google/gemini-2.0-flash-001"),False,text
186
- else:
187
- all_models_list = preferred_models
188
-
189
- # Default model value
190
- default_model = "meta-llama/llama-4-maverick:free"#preferred_models[0][1] # get free model
191
- text = f"""**Current Model**: Llama 4 Maverick (free)
192
- **Estimated cost per 100 Images**: {MODEL_PRICING["meta-llama/llama-4-maverick:free"]}"""
193
- return gr.Update(choices=preferred_models, label="Select Model",value=default_model),True,text
194
 
195
  length_choice = gr.Radio(
196
  choices=["short", "medium", "long"],
 
22
  authorized_users_str = os.environ.get("AUTHORIZED_USER_IDS", "")
23
  AUTHORIZED_USER_IDS = set(authorized_users_str.split(',') if authorized_users_str and authorized_users_str.strip() else [])
24
 
 
25
  # Define model pricing information (approximate costs per 100 image API calls)
26
  MODEL_PRICING = {
27
  "google/gemini-2.0-flash-001": "$0.03",
 
80
  filename = os.path.splitext(basename)[0]
81
  return filename
82
 
83
+ # Function to check authorization
84
+ def check_authorization(profile: gr.OAuthProfile | None):
85
+
86
+ is_authorized = profile.username in AUTHORIZED_USER_IDS
87
+ if is_authorized:
88
+ # Define preferred and additional models directly in the function
89
+ preferred_models_auth = [
90
+ ("Gemini 2.0 Flash (cheap)", "google/gemini-2.0-flash-001"),
91
+ ("GPT-4.1 Mini", "gpt-4.1-mini"),
92
+ ("GPT-4.1 (Recommended)", "gpt-4.1"),
93
+ ("Claude 3.7 Sonnet", "anthropic/claude-3.7-sonnet"),
94
+ ("Gemini 2.5 Pro", "google/gemini-2.5-pro-preview-03-25"),
95
+ ("Gemini 2.5 Flash Thinking (Recommended)","google/gemini-2.5-flash-preview")
96
+ ]
97
+
98
+ additional_models = [
99
+ ("GPT-4.1 Nano", "gpt-4.1-nano"),
100
+ ("ChatGPT Latest", "openai/chatgpt-4o-latest"),
101
+ ("Llama 4 Maverick", "meta-llama/llama-4-maverick")
102
+ ]
103
+
104
+ # Calculate all models once
105
+ all_models_list = preferred_models + additional_models
106
+
107
+ text = f"""**Current Model**: Gemini 2.0 Flash (cheap)
108
+ **Estimated cost per 100 Images**: {MODEL_PRICING["google/gemini-2.0-flash-001"]}"""
109
+
110
+ return gr.Update(choices=preferred_models_auth, label="Select Model",value="google/gemini-2.0-flash-001"),False,text
111
+ else:
112
+ all_models_list = preferred_models
113
+
114
+ # Default model value
115
+ default_model = "meta-llama/llama-4-maverick:free"#preferred_models[0][1] # get free model
116
+ text = f"""**Current Model**: Llama 4 Maverick (free)
117
+ **Estimated cost per 100 Images**: {MODEL_PRICING["meta-llama/llama-4-maverick:free"]}"""
118
+ return gr.Update(choices=preferred_models, label="Select Model",value=default_model),True,text
119
+
120
  # Define the Gradio interface
121
  def create_demo():
122
  custom_css = """
 
190
  label="Select Model",
191
  value="meta-llama/llama-4-maverick:free"
192
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
  length_choice = gr.Radio(
195
  choices=["short", "medium", "long"],