ginipick commited on
Commit
984ff0a
·
verified ·
1 Parent(s): 856c6dc

Delete app-backup1.py

Browse files
Files changed (1) hide show
  1. app-backup1.py +0 -64
app-backup1.py DELETED
@@ -1,64 +0,0 @@
1
- import requests
2
- import gradio as gr
3
- from typing import List, Dict, Union
4
-
5
- def get_most_liked_spaces(limit: int = 10) -> Union[List[Dict], str]:
6
- url = "https://huggingface.co/api/spaces"
7
- params = {
8
- "sort": "likes",
9
- "direction": -1,
10
- "limit": limit,
11
- "full": "true"
12
- }
13
-
14
- try:
15
- response = requests.get(url, params=params)
16
- response.raise_for_status()
17
- data = response.json()
18
-
19
- if isinstance(data, list):
20
- return data
21
- else:
22
- return f"Unexpected API response format: {type(data)}"
23
- except requests.RequestException as e:
24
- return f"API request error: {str(e)}"
25
- except ValueError as e:
26
- return f"JSON decoding error: {str(e)}"
27
-
28
- def format_spaces(spaces: Union[List[Dict], str]) -> str:
29
- if isinstance(spaces, str):
30
- return spaces # 이미 오류 메시지인 경우 그대로 반환
31
-
32
- output = ""
33
- for idx, space in enumerate(spaces, 1):
34
- if not isinstance(space, dict):
35
- output += f"{idx}. Unexpected space data format: {type(space)}\n\n"
36
- continue
37
-
38
- space_id = space.get('id', 'Unknown')
39
- space_name = space.get('title', space.get('name', 'Unknown'))
40
- author_data = space.get('author', {})
41
- space_author = author_data.get('name', 'Unknown') if isinstance(author_data, dict) else 'Unknown'
42
- space_likes = space.get('likes', 'N/A')
43
-
44
- output += f"{idx}. {space_name} by {space_author}\n"
45
- output += f" Likes: {space_likes}\n"
46
- output += f" URL: https://huggingface.co/spaces/{space_id}\n\n"
47
-
48
- return output if output else "No valid space data found."
49
-
50
- def get_spaces_list(limit: int) -> str:
51
- spaces = get_most_liked_spaces(limit)
52
- return format_spaces(spaces)
53
-
54
- # Gradio 인터페이스 정의
55
- iface = gr.Interface(
56
- fn=get_spaces_list,
57
- inputs=gr.Slider(minimum=1, maximum=50, step=1, label="Number of Spaces to Display", value=10),
58
- outputs="text",
59
- title="Hugging Face Most Liked Spaces",
60
- description="Display the most liked Hugging Face Spaces in descending order.",
61
- )
62
-
63
- if __name__ == "__main__":
64
- iface.launch()