Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,8 +12,6 @@ from tqdm import tqdm # For download progress bar
|
|
| 12 |
import spaces
|
| 13 |
import functools
|
| 14 |
from constants import updated_upscaler_dict as UPSCALER_DICT_GUI
|
| 15 |
-
|
| 16 |
-
# --- New Official Implementation Imports ---
|
| 17 |
from stablepy import load_upscaler_model
|
| 18 |
|
| 19 |
# --- New Global Constants ---
|
|
@@ -24,10 +22,10 @@ DIRECTORY_UPSCALERS = "upscalers"
|
|
| 24 |
# Set your Hugging Face Write Token as an environment variable
|
| 25 |
# export HF_TOKEN_ORG="hf_YourTokenHere"
|
| 26 |
HF_TOKEN_ORG = os.getenv("HF_TOKEN_ORG")
|
| 27 |
-
DATASET_REPO_ID = "TestOrganizationPleaseIgnore/
|
| 28 |
DATASET_FILENAME = "upscaler_preferences.csv"
|
| 29 |
LOCAL_CSV_PATH = "upscaler_preferences_local.csv" # Local backup for safety
|
| 30 |
-
PUSH_THRESHOLD =
|
| 31 |
|
| 32 |
# --- Helper Functions for New Implementation ---
|
| 33 |
def download_model(directory, url):
|
|
@@ -66,21 +64,6 @@ def download_model(directory, url):
|
|
| 66 |
print(f"Error downloading model: {e}")
|
| 67 |
return None
|
| 68 |
|
| 69 |
-
def extract_exif_data(image):
|
| 70 |
-
"""Placeholder function to extract EXIF data. Can be expanded later."""
|
| 71 |
-
# In a real implementation, you would use a library like piexif
|
| 72 |
-
# and return the exif bytes. For now, it does nothing.
|
| 73 |
-
return None
|
| 74 |
-
|
| 75 |
-
# def on_gpu_configurable(duration=60):
|
| 76 |
-
# def decorator(func):
|
| 77 |
-
# @functools.wraps(func)
|
| 78 |
-
# @spaces.GPU(duration=duration)
|
| 79 |
-
# def wrapper(*args, **kwargs):
|
| 80 |
-
# return func(*args, **kwargs)
|
| 81 |
-
# return wrapper
|
| 82 |
-
# return decorator
|
| 83 |
-
|
| 84 |
|
| 85 |
class UpscalerApp:
|
| 86 |
def __init__(self, repo_id, filename, local_path, push_threshold):
|
|
@@ -291,7 +274,6 @@ class UpscalerApp:
|
|
| 291 |
reveal_text = f"Thank you! Your preference for **{choice}** has been recorded.\n\n- **Image A was:** {model_a}\n- **Image B was:** {model_b}"
|
| 292 |
return reveal_text, gr.Button(interactive=False), gr.Button(interactive=False)
|
| 293 |
|
| 294 |
-
# @on_gpu_configurable(duration=59)
|
| 295 |
def playground_upscale(self, image, upscaler_name, upscaler_size, tile, tile_overlap, half):
|
| 296 |
if image is None or upscaler_name is None: return None
|
| 297 |
return self.process_upscale(image, upscaler_name, upscaler_size, tile, tile_overlap, half)
|
|
@@ -312,8 +294,10 @@ class UpscalerApp:
|
|
| 312 |
with gr.Tab("Blind Test Comparison"):
|
| 313 |
gr.Markdown("Upload an image, compare the results, and select your favorite. Your vote is recorded to rank the models.")
|
| 314 |
gr.Markdown(
|
| 315 |
-
"> **Disclaimer:** This application **does not store your uploaded images**."
|
| 316 |
-
"
|
|
|
|
|
|
|
| 317 |
)
|
| 318 |
model_a_state = gr.State("")
|
| 319 |
model_b_state = gr.State("")
|
|
|
|
| 12 |
import spaces
|
| 13 |
import functools
|
| 14 |
from constants import updated_upscaler_dict as UPSCALER_DICT_GUI
|
|
|
|
|
|
|
| 15 |
from stablepy import load_upscaler_model
|
| 16 |
|
| 17 |
# --- New Global Constants ---
|
|
|
|
| 22 |
# Set your Hugging Face Write Token as an environment variable
|
| 23 |
# export HF_TOKEN_ORG="hf_YourTokenHere"
|
| 24 |
HF_TOKEN_ORG = os.getenv("HF_TOKEN_ORG")
|
| 25 |
+
DATASET_REPO_ID = "TestOrganizationPleaseIgnore/upscale_board_data"
|
| 26 |
DATASET_FILENAME = "upscaler_preferences.csv"
|
| 27 |
LOCAL_CSV_PATH = "upscaler_preferences_local.csv" # Local backup for safety
|
| 28 |
+
PUSH_THRESHOLD = 2 # Push after this many new votes
|
| 29 |
|
| 30 |
# --- Helper Functions for New Implementation ---
|
| 31 |
def download_model(directory, url):
|
|
|
|
| 64 |
print(f"Error downloading model: {e}")
|
| 65 |
return None
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
class UpscalerApp:
|
| 69 |
def __init__(self, repo_id, filename, local_path, push_threshold):
|
|
|
|
| 274 |
reveal_text = f"Thank you! Your preference for **{choice}** has been recorded.\n\n- **Image A was:** {model_a}\n- **Image B was:** {model_b}"
|
| 275 |
return reveal_text, gr.Button(interactive=False), gr.Button(interactive=False)
|
| 276 |
|
|
|
|
| 277 |
def playground_upscale(self, image, upscaler_name, upscaler_size, tile, tile_overlap, half):
|
| 278 |
if image is None or upscaler_name is None: return None
|
| 279 |
return self.process_upscale(image, upscaler_name, upscaler_size, tile, tile_overlap, half)
|
|
|
|
| 294 |
with gr.Tab("Blind Test Comparison"):
|
| 295 |
gr.Markdown("Upload an image, compare the results, and select your favorite. Your vote is recorded to rank the models.")
|
| 296 |
gr.Markdown(
|
| 297 |
+
"> **Disclaimer:** This application **does not store your uploaded images**. "
|
| 298 |
+
"It only anonymously records which upscaler you prefer to rank them. "
|
| 299 |
+
"The collected statistics are publicly available at "
|
| 300 |
+
"[upscaler_preferences.csv](https://huggingface.co/datasets/TestOrganizationPleaseIgnore/upscale_board_data/blob/main/upscaler_preferences.csv)."
|
| 301 |
)
|
| 302 |
model_a_state = gr.State("")
|
| 303 |
model_b_state = gr.State("")
|