Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, whoami
|
3 |
from config import howManyModelsToUse,num_models,max_images,inference_timeout,MAX_SEED,thePrompt,preSetPrompt,negPreSetPrompt
|
4 |
-
from all_models import models
|
5 |
import asyncio
|
6 |
import os
|
7 |
import pandas as pd
|
@@ -10,20 +10,13 @@ from threading import RLock
|
|
10 |
lock = RLock()
|
11 |
HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None # If private or gated models aren't used, ENV setting is unnecessary.
|
12 |
# --- Step 2: Authenticate and fetch your models
|
|
|
|
|
13 |
api = HfApi()
|
14 |
user_info = whoami(token=HF_TOKEN)
|
15 |
username = user_info["name"]
|
16 |
from handle_models import load_fn,infer,gen_fn
|
17 |
from externalmod import gr_Interface_load, save_image, randomize_seed
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
def extend_choices(choices):
|
28 |
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
29 |
def update_imgbox(choices):
|
@@ -33,8 +26,15 @@ def random_choices():
|
|
33 |
import random
|
34 |
random.seed()
|
35 |
return random.choices(models, k=num_models)
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
|
@@ -49,7 +49,14 @@ load_fn(default_models,HF_TOKEN)
|
|
49 |
|
50 |
'''
|
51 |
|
|
|
|
|
52 |
with gr.Blocks(fill_width=True) as demo:
|
|
|
|
|
|
|
|
|
|
|
53 |
with gr.Tab(str(num_models) + ' Models'):
|
54 |
with gr.Column(scale=2):
|
55 |
with gr.Group():
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, whoami
|
3 |
from config import howManyModelsToUse,num_models,max_images,inference_timeout,MAX_SEED,thePrompt,preSetPrompt,negPreSetPrompt
|
4 |
+
from all_models import models
|
5 |
import asyncio
|
6 |
import os
|
7 |
import pandas as pd
|
|
|
10 |
lock = RLock()
|
11 |
HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None # If private or gated models aren't used, ENV setting is unnecessary.
|
12 |
# --- Step 2: Authenticate and fetch your models
|
13 |
+
|
14 |
+
default_models = models[:num_models]
|
15 |
api = HfApi()
|
16 |
user_info = whoami(token=HF_TOKEN)
|
17 |
username = user_info["name"]
|
18 |
from handle_models import load_fn,infer,gen_fn
|
19 |
from externalmod import gr_Interface_load, save_image, randomize_seed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def extend_choices(choices):
|
21 |
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
22 |
def update_imgbox(choices):
|
|
|
26 |
import random
|
27 |
random.seed()
|
28 |
return random.choices(models, k=num_models)
|
29 |
+
mymodels = list(api.list_models(author=username, token=HF_TOKEN))
|
30 |
+
model_ids = [m.modelId for m in mymodels]
|
31 |
+
if not model_ids:
|
32 |
+
raise ValueError(f"No models found for user '{username}'")
|
33 |
+
# --- Step 3: Build Gradio UI
|
34 |
+
def handle_model_selection(selected_models):
|
35 |
+
if not selected_models:
|
36 |
+
return "No models selected."
|
37 |
+
return "✅ Selected models:\n" + "\n".join(selected_models)
|
38 |
|
39 |
|
40 |
|
|
|
49 |
|
50 |
'''
|
51 |
|
52 |
+
|
53 |
+
|
54 |
with gr.Blocks(fill_width=True) as demo:
|
55 |
+
with gr.Accordion('Model selection'):
|
56 |
+
model_choice = gr.CheckboxGroup(models, label = f'Choose up to {int(num_models)} different models from the {len(models)} available!', value=default_models, interactive=True)
|
57 |
+
model_choice.change(update_imgbox, model_choice, output)
|
58 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
59 |
+
random_button.click(random_choices, None, model_choice)
|
60 |
with gr.Tab(str(num_models) + ' Models'):
|
61 |
with gr.Column(scale=2):
|
62 |
with gr.Group():
|