openfree commited on
Commit
5b2e51f
โ€ข
1 Parent(s): fbd7b3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -2,8 +2,8 @@ import requests
2
  import gradio as gr
3
  from datetime import datetime
4
 
5
- # ๊ณ ์ •๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„
6
- USERNAME = "openfree"
7
 
8
  def format_timestamp(timestamp):
9
  if timestamp:
@@ -42,41 +42,42 @@ def get_space_card(space):
42
  """
43
 
44
  def get_user_spaces():
45
- # ์ง์ ‘ spaces API ํ˜ธ์ถœ
46
  response = requests.get(
47
- f"https://huggingface.co/api/spaces/{USERNAME}",
 
48
  headers={"Accept": "application/json"}
49
  )
50
 
51
  # ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์ถœ๋ ฅ
52
  print(f"Status Code: {response.status_code}")
53
- print(f"Response: {response.text}")
54
 
55
  if response.status_code != 200:
56
  return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
57
 
58
  try:
59
- spaces = response.json()
60
- if not isinstance(spaces, list):
61
- spaces = [spaces]
62
  except Exception as e:
63
  return f"Error parsing response: {str(e)}"
64
 
65
- if not spaces:
66
  return "No public Spaces found for this user."
67
 
68
  # Create HTML grid layout with title and count
69
  html_content = f"""
70
  <div style='padding: 20px; background-color: #f5f5f5;'>
71
  <div style='margin-bottom: 20px;'>
72
- <p style='color: #666; margin: 0;'>Found {len(spaces)} public spaces</p>
73
  </div>
74
  <div style='
75
  display: grid;
76
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
77
  gap: 20px;
78
  '>
79
- {"".join(get_space_card(space) for space in spaces)}
80
  </div>
81
  </div>
82
  """
 
2
  import gradio as gr
3
  from datetime import datetime
4
 
5
+ # ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด ์•Œ๋ ค์ง„ ์‚ฌ์šฉ์ž๋กœ ๋ณ€๊ฒฝ
6
+ USERNAME = "multimodalart" # ๋งŽ์€ public spaces๋ฅผ ๊ฐ€์ง„ ์‚ฌ์šฉ์ž
7
 
8
  def format_timestamp(timestamp):
9
  if timestamp:
 
42
  """
43
 
44
  def get_user_spaces():
45
+ # spaces ๊ฒ€์ƒ‰ API ์‚ฌ์šฉ
46
  response = requests.get(
47
+ "https://huggingface.co/api/spaces",
48
+ params={"search": USERNAME},
49
  headers={"Accept": "application/json"}
50
  )
51
 
52
  # ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์ถœ๋ ฅ
53
  print(f"Status Code: {response.status_code}")
54
+ print(f"Response: {response.text[:500]}...") # ์‘๋‹ต์˜ ์ฒ˜์Œ 500์ž๋งŒ ์ถœ๋ ฅ
55
 
56
  if response.status_code != 200:
57
  return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
58
 
59
  try:
60
+ all_spaces = response.json()
61
+ # ํ•ด๋‹น ์‚ฌ์šฉ์ž์˜ spaces๋งŒ ํ•„ํ„ฐ๋ง
62
+ user_spaces = [space for space in all_spaces if space.get('author', '') == USERNAME]
63
  except Exception as e:
64
  return f"Error parsing response: {str(e)}"
65
 
66
+ if not user_spaces:
67
  return "No public Spaces found for this user."
68
 
69
  # Create HTML grid layout with title and count
70
  html_content = f"""
71
  <div style='padding: 20px; background-color: #f5f5f5;'>
72
  <div style='margin-bottom: 20px;'>
73
+ <p style='color: #666; margin: 0;'>Found {len(user_spaces)} public spaces for {USERNAME}</p>
74
  </div>
75
  <div style='
76
  display: grid;
77
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
78
  gap: 20px;
79
  '>
80
+ {"".join(get_space_card(space) for space in user_spaces)}
81
  </div>
82
  </div>
83
  """