Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
7ab27ea
1
Parent(s):
7a46537
fix HF API key setup
Browse files- api_config.py +1 -1
- api_core.py +12 -4
- build/web/flutter_bootstrap.js +1 -1
- build/web/flutter_service_worker.js +2 -2
- build/web/index.html +1 -1
- build/web/main.dart.js +0 -0
- lib/screens/settings_screen.dart +38 -1
- lib/screens/video_screen.dart +1 -1
api_config.py
CHANGED
@@ -181,4 +181,4 @@ CONFIG_FOR_ADMIN_HF_USERS = {
|
|
181 |
"max_clip_height": 640, # 512, # 448, # 416,
|
182 |
}
|
183 |
|
184 |
-
|
|
|
181 |
"max_clip_height": 640, # 512, # 448, # 416,
|
182 |
}
|
183 |
|
184 |
+
CONFIG_FOR_ADMIN_HF_USERS = CONFIG_FOR_PRO_HF_USERS
|
api_core.py
CHANGED
@@ -258,16 +258,24 @@ class VideoGenerationAPI:
|
|
258 |
lambda: self.hf_api.whoami(token=token)
|
259 |
)
|
260 |
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
# Determine the user role based on the information
|
264 |
user_role: UserRole
|
265 |
|
266 |
# Check if the user is an admin
|
267 |
-
if
|
268 |
user_role = 'admin'
|
269 |
# Check if the user has a pro account
|
270 |
-
elif
|
271 |
user_role = 'pro'
|
272 |
else:
|
273 |
user_role = 'normal'
|
@@ -276,7 +284,7 @@ class VideoGenerationAPI:
|
|
276 |
self.user_role_cache[token] = {
|
277 |
'role': user_role,
|
278 |
'timestamp': current_time,
|
279 |
-
'username':
|
280 |
}
|
281 |
|
282 |
return user_role
|
|
|
258 |
lambda: self.hf_api.whoami(token=token)
|
259 |
)
|
260 |
|
261 |
+
# Handle both object and dict response formats from whoami
|
262 |
+
username = user_info.get('name') if isinstance(user_info, dict) else getattr(user_info, 'name', None)
|
263 |
+
is_pro = user_info.get('is_pro') if isinstance(user_info, dict) else getattr(user_info, 'is_pro', False)
|
264 |
+
|
265 |
+
if not username:
|
266 |
+
logger.error(f"Could not determine username from user_info: {user_info}")
|
267 |
+
return 'anon'
|
268 |
+
|
269 |
+
logger.info(f"Token valid for user: {username}")
|
270 |
|
271 |
# Determine the user role based on the information
|
272 |
user_role: UserRole
|
273 |
|
274 |
# Check if the user is an admin
|
275 |
+
if username in ADMIN_ACCOUNTS:
|
276 |
user_role = 'admin'
|
277 |
# Check if the user has a pro account
|
278 |
+
elif is_pro:
|
279 |
user_role = 'pro'
|
280 |
else:
|
281 |
user_role = 'normal'
|
|
|
284 |
self.user_role_cache[token] = {
|
285 |
'role': user_role,
|
286 |
'timestamp': current_time,
|
287 |
+
'username': username
|
288 |
}
|
289 |
|
290 |
return user_role
|
build/web/flutter_bootstrap.js
CHANGED
@@ -39,6 +39,6 @@ _flutter.buildConfig = {"engineRevision":"382be0028d370607f76215a9be322e5514b263
|
|
39 |
|
40 |
_flutter.loader.load({
|
41 |
serviceWorkerSettings: {
|
42 |
-
serviceWorkerVersion: "
|
43 |
}
|
44 |
});
|
|
|
39 |
|
40 |
_flutter.loader.load({
|
41 |
serviceWorkerSettings: {
|
42 |
+
serviceWorkerVersion: "797752570"
|
43 |
}
|
44 |
});
|
build/web/flutter_service_worker.js
CHANGED
@@ -3,11 +3,11 @@ const MANIFEST = 'flutter-app-manifest';
|
|
3 |
const TEMP = 'flutter-temp-cache';
|
4 |
const CACHE_NAME = 'flutter-app-cache';
|
5 |
|
6 |
-
const RESOURCES = {"flutter_bootstrap.js": "
|
7 |
"version.json": "b5eaae4fc120710a3c35125322173615",
|
8 |
"index.html": "cd2094e3989e3eb0424e47d7d188c298",
|
9 |
"/": "cd2094e3989e3eb0424e47d7d188c298",
|
10 |
-
"main.dart.js": "
|
11 |
"flutter.js": "83d881c1dbb6d6bcd6b42e274605b69c",
|
12 |
"aitube.svg": "26140ba0d153b213b122bc6ebcc17f6c",
|
13 |
"favicon.png": "c8a183c516004e648a7bac7497c89b97",
|
|
|
3 |
const TEMP = 'flutter-temp-cache';
|
4 |
const CACHE_NAME = 'flutter-app-cache';
|
5 |
|
6 |
+
const RESOURCES = {"flutter_bootstrap.js": "1345e31de2b3abaeb866a96f3ed33f5f",
|
7 |
"version.json": "b5eaae4fc120710a3c35125322173615",
|
8 |
"index.html": "cd2094e3989e3eb0424e47d7d188c298",
|
9 |
"/": "cd2094e3989e3eb0424e47d7d188c298",
|
10 |
+
"main.dart.js": "f8d70b55b2c132f06a67b5857e1a76a9",
|
11 |
"flutter.js": "83d881c1dbb6d6bcd6b42e274605b69c",
|
12 |
"aitube.svg": "26140ba0d153b213b122bc6ebcc17f6c",
|
13 |
"favicon.png": "c8a183c516004e648a7bac7497c89b97",
|
build/web/index.html
CHANGED
@@ -156,7 +156,7 @@
|
|
156 |
</script>
|
157 |
|
158 |
<!-- Add version parameter for cache busting -->
|
159 |
-
<script src="flutter_bootstrap.js?v=
|
160 |
|
161 |
<!-- Add cache busting script -->
|
162 |
<script>
|
|
|
156 |
</script>
|
157 |
|
158 |
<!-- Add version parameter for cache busting -->
|
159 |
+
<script src="flutter_bootstrap.js?v=1746643716" async></script>
|
160 |
|
161 |
<!-- Add cache busting script -->
|
162 |
<script>
|
build/web/main.dart.js
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
lib/screens/settings_screen.dart
CHANGED
@@ -67,11 +67,48 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|
67 |
obscureText: true,
|
68 |
onChanged: (value) async {
|
69 |
await _settingsService.setHuggingfaceApiKey(value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
// Reinitialize the websocket connection when the API key changes
|
71 |
final websocket = WebSocketApiService();
|
72 |
-
|
|
|
73 |
await websocket.dispose();
|
|
|
|
|
74 |
await websocket.connect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
},
|
77 |
),
|
|
|
67 |
obscureText: true,
|
68 |
onChanged: (value) async {
|
69 |
await _settingsService.setHuggingfaceApiKey(value);
|
70 |
+
|
71 |
+
// Show a snackbar to indicate the API key was saved
|
72 |
+
if (context.mounted) {
|
73 |
+
ScaffoldMessenger.of(context).showSnackBar(
|
74 |
+
const SnackBar(
|
75 |
+
content: Text('API Key saved. Reconnecting...'),
|
76 |
+
duration: Duration(seconds: 2),
|
77 |
+
),
|
78 |
+
);
|
79 |
+
}
|
80 |
+
|
81 |
// Reinitialize the websocket connection when the API key changes
|
82 |
final websocket = WebSocketApiService();
|
83 |
+
try {
|
84 |
+
// First dispose the current connection
|
85 |
await websocket.dispose();
|
86 |
+
|
87 |
+
// Then create a new connection with the new API key
|
88 |
await websocket.connect();
|
89 |
+
|
90 |
+
// Finally, initialize the connection completely
|
91 |
+
await websocket.initialize();
|
92 |
+
|
93 |
+
// Show success message
|
94 |
+
if (context.mounted) {
|
95 |
+
ScaffoldMessenger.of(context).showSnackBar(
|
96 |
+
const SnackBar(
|
97 |
+
content: Text('Connected successfully with new API key'),
|
98 |
+
backgroundColor: Colors.green,
|
99 |
+
),
|
100 |
+
);
|
101 |
+
}
|
102 |
+
} catch (e) {
|
103 |
+
// Show error message if connection fails
|
104 |
+
if (context.mounted) {
|
105 |
+
ScaffoldMessenger.of(context).showSnackBar(
|
106 |
+
SnackBar(
|
107 |
+
content: Text('Failed to connect: $e'),
|
108 |
+
backgroundColor: Colors.red,
|
109 |
+
),
|
110 |
+
);
|
111 |
+
}
|
112 |
}
|
113 |
},
|
114 |
),
|
lib/screens/video_screen.dart
CHANGED
@@ -511,7 +511,7 @@ class _VideoScreenState extends State<VideoScreen> {
|
|
511 |
IconButton(
|
512 |
icon: const Icon(Icons.share, color: AiTubeColors.primary),
|
513 |
onPressed: _shareVideo,
|
514 |
-
tooltip: 'Share
|
515 |
),
|
516 |
],
|
517 |
),
|
|
|
511 |
IconButton(
|
512 |
icon: const Icon(Icons.share, color: AiTubeColors.primary),
|
513 |
onPressed: _shareVideo,
|
514 |
+
tooltip: 'Share prompt',
|
515 |
),
|
516 |
],
|
517 |
),
|