openfree commited on
Commit
6d77ca6
โ€ข
1 Parent(s): a7a154b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -59
app.py CHANGED
@@ -3,7 +3,6 @@ import gradio as gr
3
  from datetime import datetime
4
 
5
  USERNAME = "openfree"
6
- LIMIT = 100 # ํ•œ ๋ฒˆ์— ๊ฐ€์ ธ์˜ฌ ์ตœ๋Œ€ spaces ์ˆ˜
7
 
8
  def format_timestamp(timestamp):
9
  if timestamp:
@@ -52,53 +51,25 @@ def get_space_card(space):
52
  </div>
53
  """
54
 
55
- def get_all_user_spaces():
56
- """Get all spaces for a user with pagination"""
57
- all_spaces = []
58
- offset = 0
59
-
60
- while True:
61
- url = f"https://huggingface.co/api/spaces"
62
- params = {
63
- "limit": LIMIT,
64
- "offset": offset,
65
- "full": "true"
66
- }
67
- headers = {
68
- "Accept": "application/json",
69
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
70
- }
71
-
72
- try:
73
- response = requests.get(url, params=params, headers=headers)
74
- if response.status_code != 200:
75
- print(f"Error: Status Code {response.status_code}")
76
- break
77
-
78
- spaces_data = response.json()
79
- if not spaces_data:
80
- break
81
-
82
- # Filter spaces for the specific user
83
- user_spaces = [space for space in spaces_data if space.get('id', '').startswith(f"{USERNAME}/")]
84
- all_spaces.extend(user_spaces)
85
-
86
- # If we got less than the limit, we've reached the end
87
- if len(spaces_data) < LIMIT:
88
- break
89
-
90
- offset += LIMIT
91
 
92
- except Exception as e:
93
- print(f"Error fetching spaces: {e}")
94
- break
 
95
 
96
- return all_spaces
 
97
 
98
- def get_user_spaces():
99
- try:
100
- # Get all spaces for the user
101
- user_spaces = get_all_user_spaces()
102
 
103
  if not user_spaces:
104
  return f"""
@@ -141,20 +112,16 @@ def get_user_spaces():
141
  </div>
142
  """
143
 
144
- # Creating the Gradio interface
145
- app = gr.Interface(
146
- fn=get_user_spaces,
147
- inputs=None,
148
- outputs=gr.HTML(),
149
- title=f"Hugging Face Spaces Dashboard - {USERNAME}",
150
- description=f"Displays public Spaces from {USERNAME}",
151
- theme=gr.themes.Soft(),
152
- css="""
153
- .gradio-container {
154
- max-width: 100% !important;
155
- }
156
- """
157
- )
158
 
159
  # Launch the Gradio app
160
  if __name__ == "__main__":
 
3
  from datetime import datetime
4
 
5
  USERNAME = "openfree"
 
6
 
7
  def format_timestamp(timestamp):
8
  if timestamp:
 
51
  </div>
52
  """
53
 
54
+ def get_user_spaces():
55
+ url = f"https://huggingface.co/api/spaces?author={USERNAME}&limit=500" # API ์ฟผ๋ฆฌ ์ˆ˜์ •
56
+ headers = {
57
+ "Accept": "application/json",
58
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
59
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ try:
62
+ response = requests.get(url, headers=headers)
63
+ print(f"Status Code: {response.status_code}")
64
+ print(f"Response length: {len(response.json()) if response.status_code == 200 else 'N/A'}")
65
 
66
+ if response.status_code != 200:
67
+ return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
68
 
69
+ spaces_data = response.json()
70
+
71
+ # Filter spaces for the specific user (although API should already filter)
72
+ user_spaces = spaces_data
73
 
74
  if not user_spaces:
75
  return f"""
 
112
  </div>
113
  """
114
 
115
+ # Creating the Gradio interface with automatic refresh
116
+ with gr.Blocks() as app:
117
+ html_output = gr.HTML()
118
+
119
+ # ์‹œ์ž‘ํ•  ๋•Œ ์ž๋™์œผ๋กœ ๋ฐ์ดํ„ฐ ๋กœ๋“œ
120
+ gr.on(
121
+ triggers=[], # ๋นˆ triggers๋Š” ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ ์‹คํ–‰์„ ์˜๋ฏธ
122
+ fn=get_user_spaces,
123
+ outputs=[html_output],
124
+ )
 
 
 
 
125
 
126
  # Launch the Gradio app
127
  if __name__ == "__main__":