File size: 5,268 Bytes
0af19e2
a058847
47c1984
2fb46eb
 
 
 
 
47c1984
cedfc4e
b59fc65
0af19e2
 
a058847
 
 
 
c1158cf
 
 
 
 
 
 
 
 
a058847
4a26907
2102432
 
a058847
 
 
 
 
 
 
3cc7736
0af19e2
0ed58ab
 
c6217e4
0ed58ab
0af19e2
 
 
caac55e
3cc7736
 
 
 
a058847
 
 
3cc7736
c6217e4
0af19e2
 
0ed58ab
0af19e2
 
e8d215b
 
0af19e2
 
 
 
 
 
 
 
 
c6217e4
0ed58ab
0af19e2
 
 
c6217e4
0af19e2
 
 
 
 
 
c6217e4
0af19e2
 
 
 
 
 
2fb46eb
cd37c13
0af19e2
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gradio as gr
from huggingface_hub import HfApi, whoami
howManyModelsToUse = 20
num_models = howManyModelsToUse
max_images = howManyModelsToUse
inference_timeout = 60
default_models = models[:num_models]
MAX_SEED = 2**32-1
thePrompt ="group of 3boys kissing in bathtub while interracial daddy gives a boy a handjob"
preSetPrompt = thePrompt
negPreSetPrompt = "[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, text, fuzziness, asian, african, collage, composite, combined image"
lock = RLock()
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.
# --- Step 2: Authenticate and fetch your models
api = HfApi()
user_info = whoami(token=HF_TOKEN)
username = user_info["name"]
from handle_models import load_fn,infer,gen_fn
from all_models import models
from externalmod import gr_Interface_load, save_image, randomize_seed
import asyncio
import os
from threading import RLock
from datetime import datetime
from handlemodelradio import extend_choices,update_imgbox,random_choices
#anything but huggingface_hub==0.26.2 will result in token error
# Get all models owned by the user
#models = api.list_models(author=username, token=HF_TOKEN)
mymodels = list(api.list_models(author=username, token=HF_TOKEN))
model_ids = [m.modelId for m in mymodels]
if not model_ids:
    raise ValueError(f"No models found for user '{username}'")
# --- Step 3: Build Gradio UI
def handle_model_selection(selected_models):
    if not selected_models:
        return "No models selected."
    return "✅ Selected models:\n" + "\n".join(selected_models)


def get_current_time():
    now = datetime.now()
    current_time = now.strftime("%y-%m-%d %H:%M:%S")
    return current_time
load_fn(models)


'''
 
'''
with gr.Blocks(fill_width=True) as demo:
    with gr.Row():
        gr.Markdown(f"# ({username}) you are logged in")
        model_selector = gr.CheckboxGroup(choices=model_ids,value=model_ids, label="your models",        interactive=True,    )
        output_box = gr.Textbox(lines=10, label="Selected Models")
        model_selector.change(fn=handle_model_selection, inputs=model_selector, outputs=output_box)   
    with gr.Tab(str(num_models) + ' Models'):
        with gr.Column(scale=2):
            with gr.Group():
                txt_input = gr.Textbox(label='Your prompt:', value=preSetPrompt, lines=3, autofocus=1)
                with gr.Accordion("Advanced", open=False, visible=True):
                    with gr.Row():
                        neg_input = gr.Textbox(label='Negative prompt:', value=negPreSetPrompt, lines=1)
                    with gr.Row():    
                        width = gr.Slider(label="Width", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
                        height = gr.Slider(label="Height", info="If 0, the default value is used.", maximum=1216, step=32, value=0)
                    with gr.Row():
                        steps = gr.Slider(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
                        cfg = gr.Slider(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
                        seed = gr.Slider(label="Seed", info="Randomize Seed if -1.", minimum=-1, maximum=MAX_SEED, step=1, value=-1)
                        seed_rand = gr.Button("Randomize Seed 🎲", size="sm", variant="secondary")
                        seed_rand.click(randomize_seed, None, [seed], queue=False)
            with gr.Row():
                gen_button = gr.Button(f'Generate up to {int(num_models)} images', variant='primary', scale=3, elem_classes=["butt"])
                random_button = gr.Button(f'Randomize Models', variant='secondary', scale=1)
        with gr.Column(scale=1):
            with gr.Group():
                with gr.Row():
                    output = [gr.Image(label=m, show_download_button=True, elem_classes=["image-monitor"],
                              interactive=False, width=112, height=112, show_share_button=False, format="png",
                              visible=True) for m in default_models]
                    current_models = [gr.Textbox(m, visible=False) for m in default_models]
        for m, o in zip(current_models, output):
            gen_event = gr.on(triggers=[gen_button.click, txt_input.submit], fn=gen_fn,
                              inputs=[m, txt_input, neg_input, height, width, steps, cfg, seed], outputs=[o],
                              concurrency_limit=None, queue=False)
        with gr.Column(scale=4):
            with gr.Accordion('Model selection'):
                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)
                model_choice.change(update_imgbox, model_choice, output)
                model_choice.change(extend_choices, model_choice, current_models)
                random_button.click(random_choices, None, model_choice)
    
            

demo.launch(show_api=False, max_threads=400)