Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, whoami
|
3 |
from all_models import models
|
|
|
|
|
|
|
|
|
4 |
howManyModelsToUse = 20
|
5 |
num_models = howManyModelsToUse
|
6 |
max_images = howManyModelsToUse
|
@@ -19,10 +23,6 @@ user_info = whoami(token=HF_TOKEN)
|
|
19 |
username = user_info["name"]
|
20 |
from handle_models import load_fn,infer,gen_fn
|
21 |
from externalmod import gr_Interface_load, save_image, randomize_seed
|
22 |
-
import asyncio
|
23 |
-
import os
|
24 |
-
|
25 |
-
from datetime import datetime
|
26 |
from handlemodelradio import extend_choices,update_imgbox,random_choices
|
27 |
#anything but huggingface_hub==0.26.2 will result in token error
|
28 |
# Get all models owned by the user
|
@@ -94,3 +94,47 @@ with gr.Blocks(fill_width=True) as demo:
|
|
94 |
|
95 |
|
96 |
demo.launch(show_api=False, max_threads=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, whoami
|
3 |
from all_models import models
|
4 |
+
import asyncio
|
5 |
+
import os
|
6 |
+
import pandas as pd
|
7 |
+
from datetime import datetime
|
8 |
howManyModelsToUse = 20
|
9 |
num_models = howManyModelsToUse
|
10 |
max_images = howManyModelsToUse
|
|
|
23 |
username = user_info["name"]
|
24 |
from handle_models import load_fn,infer,gen_fn
|
25 |
from externalmod import gr_Interface_load, save_image, randomize_seed
|
|
|
|
|
|
|
|
|
26 |
from handlemodelradio import extend_choices,update_imgbox,random_choices
|
27 |
#anything but huggingface_hub==0.26.2 will result in token error
|
28 |
# Get all models owned by the user
|
|
|
94 |
|
95 |
|
96 |
demo.launch(show_api=False, max_threads=400)
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
'''
|
117 |
+
|
118 |
+
# --- Step 2: Fetch user's Spaces
|
119 |
+
spaces = list(api.list_spaces(author=username, token=HF_TOKEN))
|
120 |
+
space_df = pd.DataFrame([{"Space Name": f"<a href='#' data-space='{space.id}'>{space.id.split('/')[-1]}</a>",
|
121 |
+
"Last Modified": space.lastModified,} for space in spaces])
|
122 |
+
|
123 |
+
def load_space_files(evt: gr.SelectData):
|
124 |
+
clicked_html = evt.value
|
125 |
+
space_id = clicked_html.split("data-space='")[1].split("'")[0]
|
126 |
+
files = api.list_repo_files(repo_id=space_id, repo_type="space", token=HF_TOKEN)
|
127 |
+
file_df = pd.DataFrame([{ "File": f"<a href='https://huggingface.co/spaces/{username}/{space_id.split('/')[-1]}/edit/main/{file}' target='_blank'>{file}</a>"
|
128 |
+
} for file in files])
|
129 |
+
return file_df
|
130 |
+
|
131 |
+
# --- Step 4: Build Gradio interface
|
132 |
+
gr.Markdown(f"# Hugging Face Spaces for `{username}`")
|
133 |
+
with gr.Row():
|
134 |
+
left_df = gr.Dataframe(value=space_df, label="Your Spaces (click a name)",
|
135 |
+
interactive=False, datatype="str", max_rows=len(space_df), wrap=True )
|
136 |
+
right_df = gr.Dataframe( value=pd.DataFrame(columns=["File"]),
|
137 |
+
label="Files in Selected Space", interactive=False, wrap=True )
|
138 |
+
|
139 |
+
left_df.select(fn=load_space_files, outputs=right_df)
|
140 |
+
'''
|