Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,8 +14,14 @@ import gradio as gr
|
|
| 14 |
|
| 15 |
USERNAME = "openfree"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
def take_screenshot(url):
|
| 18 |
"""웹사이트 스크린샷 촬영"""
|
|
|
|
|
|
|
|
|
|
| 19 |
if not url.startswith('http'):
|
| 20 |
url = f"https://{url}"
|
| 21 |
|
|
@@ -35,9 +41,11 @@ def take_screenshot(url):
|
|
| 35 |
img = Image.open(BytesIO(screenshot))
|
| 36 |
buffered = BytesIO()
|
| 37 |
img.save(buffered, format="PNG")
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
-
print(f"Screenshot error: {str(e)}")
|
| 41 |
return None
|
| 42 |
finally:
|
| 43 |
if 'driver' in locals():
|
|
@@ -46,8 +54,9 @@ def take_screenshot(url):
|
|
| 46 |
def get_pastel_color(index):
|
| 47 |
"""인덱스 기반 파스텔 색상 생성"""
|
| 48 |
pastel_colors = [
|
| 49 |
-
'
|
| 50 |
-
'
|
|
|
|
| 51 |
]
|
| 52 |
return pastel_colors[index % len(pastel_colors)]
|
| 53 |
|
|
@@ -57,15 +66,46 @@ def get_space_card(space, index):
|
|
| 57 |
space_name = space_id.split('/')[-1]
|
| 58 |
likes = space.get('likes', 0)
|
| 59 |
sdk = space.get('sdk', 'N/A')
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
return f"""
|
| 63 |
-
<div style='
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
</div>
|
| 70 |
"""
|
| 71 |
|
|
@@ -76,9 +116,17 @@ def get_user_spaces():
|
|
| 76 |
response = requests.get(url)
|
| 77 |
if response.status_code == 200:
|
| 78 |
spaces_data = response.json()
|
| 79 |
-
html_content = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
html_content += "".join(get_space_card(space, idx) for idx, space in enumerate(spaces_data))
|
| 81 |
-
html_content += "</div>"
|
| 82 |
return html_content
|
| 83 |
return "<p>Failed to fetch spaces</p>"
|
| 84 |
except Exception as e:
|
|
@@ -89,7 +137,11 @@ demo = gr.Interface(
|
|
| 89 |
fn=lambda: get_user_spaces(),
|
| 90 |
inputs=None,
|
| 91 |
outputs=gr.HTML(),
|
| 92 |
-
title="Hugging Face Spaces Gallery"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
|
|
|
| 14 |
|
| 15 |
USERNAME = "openfree"
|
| 16 |
|
| 17 |
+
# 스크린샷 캐시 저장소
|
| 18 |
+
SCREENSHOT_CACHE = {}
|
| 19 |
+
|
| 20 |
def take_screenshot(url):
|
| 21 |
"""웹사이트 스크린샷 촬영"""
|
| 22 |
+
if url in SCREENSHOT_CACHE:
|
| 23 |
+
return SCREENSHOT_CACHE[url]
|
| 24 |
+
|
| 25 |
if not url.startswith('http'):
|
| 26 |
url = f"https://{url}"
|
| 27 |
|
|
|
|
| 41 |
img = Image.open(BytesIO(screenshot))
|
| 42 |
buffered = BytesIO()
|
| 43 |
img.save(buffered, format="PNG")
|
| 44 |
+
base64_image = base64.b64encode(buffered.getvalue()).decode()
|
| 45 |
+
SCREENSHOT_CACHE[url] = base64_image
|
| 46 |
+
return base64_image
|
| 47 |
except Exception as e:
|
| 48 |
+
print(f"Screenshot error for {url}: {str(e)}")
|
| 49 |
return None
|
| 50 |
finally:
|
| 51 |
if 'driver' in locals():
|
|
|
|
| 54 |
def get_pastel_color(index):
|
| 55 |
"""인덱스 기반 파스텔 색상 생성"""
|
| 56 |
pastel_colors = [
|
| 57 |
+
'rgba(255, 230, 230, 0.8)', 'rgba(255, 230, 255, 0.8)',
|
| 58 |
+
'rgba(230, 230, 255, 0.8)', 'rgba(230, 255, 255, 0.8)',
|
| 59 |
+
'rgba(230, 255, 230, 0.8)'
|
| 60 |
]
|
| 61 |
return pastel_colors[index % len(pastel_colors)]
|
| 62 |
|
|
|
|
| 66 |
space_name = space_id.split('/')[-1]
|
| 67 |
likes = space.get('likes', 0)
|
| 68 |
sdk = space.get('sdk', 'N/A')
|
| 69 |
+
url = f"https://huggingface.co/spaces/{space_id}"
|
| 70 |
+
|
| 71 |
+
# 스크린샷 가져오기
|
| 72 |
+
screenshot = take_screenshot(url)
|
| 73 |
+
bg_style = f"""
|
| 74 |
+
background-image: linear-gradient(
|
| 75 |
+
{get_pastel_color(index)},
|
| 76 |
+
{get_pastel_color(index)}
|
| 77 |
+
), url(data:image/png;base64,{screenshot});
|
| 78 |
+
background-size: cover;
|
| 79 |
+
background-position: center;
|
| 80 |
+
background-blend-mode: overlay;
|
| 81 |
+
""" if screenshot else f"background-color: {get_pastel_color(index)};"
|
| 82 |
|
| 83 |
return f"""
|
| 84 |
+
<div style='
|
| 85 |
+
border: none;
|
| 86 |
+
padding: 20px;
|
| 87 |
+
margin: 10px;
|
| 88 |
+
border-radius: 15px;
|
| 89 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 90 |
+
{bg_style}
|
| 91 |
+
transition: transform 0.3s ease;
|
| 92 |
+
cursor: pointer;
|
| 93 |
+
position: relative;
|
| 94 |
+
overflow: hidden;
|
| 95 |
+
min-height: 200px;'
|
| 96 |
+
onclick="window.open('{url}', '_blank')"
|
| 97 |
+
onmouseover="this.style.transform='scale(1.02)'"
|
| 98 |
+
onmouseout="this.style.transform='scale(1)'">
|
| 99 |
+
|
| 100 |
+
<div style='
|
| 101 |
+
background: rgba(255, 255, 255, 0.9);
|
| 102 |
+
padding: 15px;
|
| 103 |
+
border-radius: 10px;
|
| 104 |
+
backdrop-filter: blur(5px);'>
|
| 105 |
+
<h3 style='margin: 0; color: #333;'>{space_name}</h3>
|
| 106 |
+
<p style='margin: 10px 0; color: #666;'>SDK: {sdk}</p>
|
| 107 |
+
<p style='margin: 10px 0; color: #666;'>❤️ {likes}</p>
|
| 108 |
+
</div>
|
| 109 |
</div>
|
| 110 |
"""
|
| 111 |
|
|
|
|
| 116 |
response = requests.get(url)
|
| 117 |
if response.status_code == 200:
|
| 118 |
spaces_data = response.json()
|
| 119 |
+
html_content = """
|
| 120 |
+
<div style='
|
| 121 |
+
padding: 20px;
|
| 122 |
+
background: #f5f5f5;'>
|
| 123 |
+
<div style='
|
| 124 |
+
display: grid;
|
| 125 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 126 |
+
gap: 20px;'>
|
| 127 |
+
"""
|
| 128 |
html_content += "".join(get_space_card(space, idx) for idx, space in enumerate(spaces_data))
|
| 129 |
+
html_content += "</div></div>"
|
| 130 |
return html_content
|
| 131 |
return "<p>Failed to fetch spaces</p>"
|
| 132 |
except Exception as e:
|
|
|
|
| 137 |
fn=lambda: get_user_spaces(),
|
| 138 |
inputs=None,
|
| 139 |
outputs=gr.HTML(),
|
| 140 |
+
title="Hugging Face Spaces Gallery",
|
| 141 |
+
css="""
|
| 142 |
+
.container { max-width: 1200px; margin: 0 auto; }
|
| 143 |
+
.gradio-container { font-family: 'Arial', sans-serif; }
|
| 144 |
+
"""
|
| 145 |
)
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|