charliebaby2023 commited on
Commit
a058847
·
verified ·
1 Parent(s): 4c344db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -6,13 +6,35 @@ import asyncio
6
  import os
7
  from threading import RLock
8
  from datetime import datetime
 
 
 
 
 
 
 
 
 
9
 
10
  preSetPrompt = thePrompt
11
  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"
12
-
13
  lock = RLock()
14
-
15
  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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def get_current_time():
18
  now = datetime.now()
@@ -109,6 +131,12 @@ def gen_fn(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, see
109
 
110
 
111
  with gr.Blocks(fill_width=True) as demo:
 
 
 
 
 
 
112
  with gr.Tab(str(num_models) + ' Models'):
113
  with gr.Column(scale=2):
114
  with gr.Group():
 
6
  import os
7
  from threading import RLock
8
  from datetime import datetime
9
+ import gradio as gr
10
+ from huggingface_hub import HfApi, whoami
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
 
19
  preSetPrompt = thePrompt
20
  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"
 
21
  lock = RLock()
 
22
  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.
23
+ # --- Step 2: Authenticate and fetch your models
24
+ api = HfApi()
25
+ user_info = whoami(token=HF_TOKEN)
26
+ username = user_info["name"]
27
+ # Get all models owned by the user
28
+ models = api.list_models(author=username, token=HF_TOKEN)
29
+ model_ids = [m.modelId for m in models]
30
+ if not model_ids:
31
+ raise ValueError(f"No models found for user '{username}'")
32
+ # --- Step 3: Build Gradio UI
33
+ def handle_model_selection(selected_models):
34
+ if not selected_models:
35
+ return "No models selected."
36
+ return "✅ Selected models:\n" + "\n".join(selected_models)
37
+
38
 
39
  def get_current_time():
40
  now = datetime.now()
 
131
 
132
 
133
  with gr.Blocks(fill_width=True) as demo:
134
+ with gr.Row():
135
+ gr.Markdown(f"# ({username}) you are logged in")
136
+ model_selector = gr.CheckboxGroup(choices=model_ids,value=model_ids, label="your models", interactive=True, )
137
+ output_box = gr.Textbox(lines=10, label="Selected Models")
138
+ model_selector.change(fn=handle_model_selection, inputs=model_selector, outputs=output_box)
139
+
140
  with gr.Tab(str(num_models) + ' Models'):
141
  with gr.Column(scale=2):
142
  with gr.Group():