user_history update
Browse files- app.py +2 -2
- modules/user_history.py +16 -8
app.py
CHANGED
|
@@ -463,9 +463,9 @@ def predict(
|
|
| 463 |
if not isinstance(seed_used, (int, float)): # Allow float for seed then cast later
|
| 464 |
raise gr.Error(f"MCP tool returned a non-numeric seed. Received type: {type(seed_used)}, value: {seed_used}")
|
| 465 |
|
| 466 |
-
if isinstance(waveform_video_path, str) and (waveform_video_path.startswith("http://"
|
| 467 |
waveform_video_path = str(download_and_save_file(waveform_video_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 468 |
-
if isinstance(wave_file_path, str) and (wave_file_path.startswith("http://"
|
| 469 |
wave_file_path = str(download_and_save_file(wave_file_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 470 |
|
| 471 |
return waveform_video_path, wave_file_path, int(seed_used)
|
|
|
|
| 463 |
if not isinstance(seed_used, (int, float)): # Allow float for seed then cast later
|
| 464 |
raise gr.Error(f"MCP tool returned a non-numeric seed. Received type: {type(seed_used)}, value: {seed_used}")
|
| 465 |
|
| 466 |
+
if isinstance(waveform_video_path, str) and (waveform_video_path.startswith("http://") or waveform_video_path.startswith("https://")):
|
| 467 |
waveform_video_path = str(download_and_save_file(waveform_video_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 468 |
+
if isinstance(wave_file_path, str) and (wave_file_path.startswith("http://") or wave_file_path.startswith("https://")):
|
| 469 |
wave_file_path = str(download_and_save_file(wave_file_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 470 |
|
| 471 |
return waveform_video_path, wave_file_path, int(seed_used)
|
modules/user_history.py
CHANGED
|
@@ -18,7 +18,7 @@ Useful links:
|
|
| 18 |
Update by Surn (Charles Fettinger)
|
| 19 |
"""
|
| 20 |
|
| 21 |
-
__version__ = "0.3.
|
| 22 |
|
| 23 |
import json
|
| 24 |
import os
|
|
@@ -173,7 +173,7 @@ def save_image(
|
|
| 173 |
# Ignore images from logged out users
|
| 174 |
if profile is None:
|
| 175 |
return
|
| 176 |
-
username = profile["preferred_username"]
|
| 177 |
|
| 178 |
# Ignore images if user history not used
|
| 179 |
user_history = _UserHistory()
|
|
@@ -210,7 +210,7 @@ def save_file(
|
|
| 210 |
# Ignore files from logged out users
|
| 211 |
if profile is None:
|
| 212 |
return
|
| 213 |
-
username = profile["preferred_username"]
|
| 214 |
|
| 215 |
# Ignore files if user history not used
|
| 216 |
user_history = _UserHistory()
|
|
@@ -406,7 +406,7 @@ def _fetch_user_history(profile: gr.OAuthProfile | None) -> List[Tuple[str, str]
|
|
| 406 |
if profile is None:
|
| 407 |
user_profile = gr.State(None)
|
| 408 |
return []
|
| 409 |
-
username = str(profile["preferred_username"])
|
| 410 |
|
| 411 |
user_profile = gr.State(profile)
|
| 412 |
|
|
@@ -442,7 +442,7 @@ def _export_user_history(profile: gr.OAuthProfile | None) -> Dict | None:
|
|
| 442 |
# Cannot load history for logged out users
|
| 443 |
if profile is None:
|
| 444 |
return None
|
| 445 |
-
username = profile["preferred_username"]
|
| 446 |
|
| 447 |
user_history = _UserHistory()
|
| 448 |
if not user_history.initialized:
|
|
@@ -471,7 +471,7 @@ def _delete_user_history(profile: gr.OAuthProfile | None) -> None:
|
|
| 471 |
# Cannot load history for logged out users
|
| 472 |
if profile is None:
|
| 473 |
return
|
| 474 |
-
username = profile["preferred_username"]
|
| 475 |
|
| 476 |
user_history = _UserHistory()
|
| 477 |
if not user_history.initialized:
|
|
@@ -489,10 +489,16 @@ def _delete_user_history(profile: gr.OAuthProfile | None) -> None:
|
|
| 489 |
|
| 490 |
def _copy_image(image: Image.Image | np.ndarray | str | Path, dst_folder: Path, uniqueId: str = "") -> Path:
|
| 491 |
try:
|
|
|
|
| 492 |
"""Copy image to the images folder."""
|
| 493 |
-
#
|
| 494 |
if isinstance(image, str):
|
| 495 |
-
image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
if isinstance(image, Path):
|
| 497 |
dst = dst_folder / Path(f"{uniqueId}_{Path(image).name}") # keep file ext
|
| 498 |
shutil.copyfile(image, dst)
|
|
@@ -653,6 +659,8 @@ def _display_if_admin() -> Callable:
|
|
| 653 |
return ""
|
| 654 |
if profile["preferred_username"] in _fetch_admins():
|
| 655 |
return _admin_content()
|
|
|
|
|
|
|
| 656 |
return ""
|
| 657 |
|
| 658 |
return _inner
|
|
|
|
| 18 |
Update by Surn (Charles Fettinger)
|
| 19 |
"""
|
| 20 |
|
| 21 |
+
__version__ = "0.3.8"
|
| 22 |
|
| 23 |
import json
|
| 24 |
import os
|
|
|
|
| 173 |
# Ignore images from logged out users
|
| 174 |
if profile is None:
|
| 175 |
return
|
| 176 |
+
username = profile if isinstance(profile, str) else profile["preferred_username"]
|
| 177 |
|
| 178 |
# Ignore images if user history not used
|
| 179 |
user_history = _UserHistory()
|
|
|
|
| 210 |
# Ignore files from logged out users
|
| 211 |
if profile is None:
|
| 212 |
return
|
| 213 |
+
username = profile if isinstance(profile, str) else profile["preferred_username"]
|
| 214 |
|
| 215 |
# Ignore files if user history not used
|
| 216 |
user_history = _UserHistory()
|
|
|
|
| 406 |
if profile is None:
|
| 407 |
user_profile = gr.State(None)
|
| 408 |
return []
|
| 409 |
+
username = profile if isinstance(profile, str) else str(profile["preferred_username"])
|
| 410 |
|
| 411 |
user_profile = gr.State(profile)
|
| 412 |
|
|
|
|
| 442 |
# Cannot load history for logged out users
|
| 443 |
if profile is None:
|
| 444 |
return None
|
| 445 |
+
username = profile if isinstance(profile, str) else profile["preferred_username"]
|
| 446 |
|
| 447 |
user_history = _UserHistory()
|
| 448 |
if not user_history.initialized:
|
|
|
|
| 471 |
# Cannot load history for logged out users
|
| 472 |
if profile is None:
|
| 473 |
return
|
| 474 |
+
username = profile if isinstance(profile, str) else profile["preferred_username"]
|
| 475 |
|
| 476 |
user_history = _UserHistory()
|
| 477 |
if not user_history.initialized:
|
|
|
|
| 489 |
|
| 490 |
def _copy_image(image: Image.Image | np.ndarray | str | Path, dst_folder: Path, uniqueId: str = "") -> Path:
|
| 491 |
try:
|
| 492 |
+
dst = dst_folder
|
| 493 |
"""Copy image to the images folder."""
|
| 494 |
+
# If image is a string, check if it's a URL.
|
| 495 |
if isinstance(image, str):
|
| 496 |
+
if image.startswith("http://") or image.startswith("https://"):
|
| 497 |
+
return _download_and_save_image(image, dst_folder)
|
| 498 |
+
else:
|
| 499 |
+
# Assume it's a local filepath string.
|
| 500 |
+
image = Path(image)
|
| 501 |
+
|
| 502 |
if isinstance(image, Path):
|
| 503 |
dst = dst_folder / Path(f"{uniqueId}_{Path(image).name}") # keep file ext
|
| 504 |
shutil.copyfile(image, dst)
|
|
|
|
| 659 |
return ""
|
| 660 |
if profile["preferred_username"] in _fetch_admins():
|
| 661 |
return _admin_content()
|
| 662 |
+
if profile in _fetch_admins():
|
| 663 |
+
return _admin_content()
|
| 664 |
return ""
|
| 665 |
|
| 666 |
return _inner
|