uratmangun commited on
Commit
cf28a97
·
verified ·
1 Parent(s): 9710105

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .gitignore +148 -0
  2. .gradio/certificate.pem +31 -0
  3. README.md +9 -5
  4. app.py +200 -0
  5. requirements.txt +59 -0
.gitignore ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ share/python-wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a script, but they may be committed by
30
+ # accident.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ .pytest_cache/
46
+ .hypothesis/
47
+ pytestdebug.log
48
+
49
+ # Translations
50
+ *.mo
51
+ *.pot
52
+
53
+ # Django stuff:
54
+ *.log
55
+ local_settings.py
56
+ db.sqlite3
57
+ db.sqlite3-journal
58
+
59
+ # Flask stuff:
60
+ instance/
61
+ .webassets-cache
62
+
63
+ # Scrapy stuff:
64
+ .scrapy
65
+
66
+ # Sphinx documentation
67
+ docs/_build/
68
+
69
+ # PyBuilder
70
+ target/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # IPython
76
+ profile_default/
77
+ ipython_config.py
78
+
79
+ # PEP 582; __pypackages__ directory
80
+ __pypackages__/
81
+
82
+ # Celery stuff
83
+ celerybeat-schedule
84
+ celerybeat.pid
85
+
86
+ # SageMath files
87
+ *.sage.py
88
+
89
+ # Environments
90
+ .env
91
+ .venv
92
+ venv/
93
+ ENV/
94
+ env/
95
+ ENV.bak/
96
+ venv.bak/
97
+
98
+ # Spyder project settings
99
+ .spyderproject
100
+ .spyproject
101
+
102
+ # Rope project settings
103
+ .ropeproject
104
+
105
+ # mkdocs documentation
106
+ /site
107
+
108
+ # mypy
109
+ .mypy_cache/
110
+ .dmypy.json
111
+ dmypy.json
112
+
113
+ # Pyre type checker
114
+ .pyre/
115
+
116
+ # pytype static analyzer
117
+ .pytype/
118
+
119
+ # Cython debug symbols
120
+ cython_debug/
121
+
122
+ # VSCode settings
123
+ .vscode/
124
+
125
+ # Editor-specific files
126
+ *.swp
127
+ *~
128
+ .DS_Store
129
+
130
+ # Secrets - add any files containing secrets here
131
+ secrets.py
132
+ .secrets
133
+ *.local
134
+
135
+ # Logs
136
+ logs/
137
+ *.log
138
+
139
+ # OS generated files
140
+ .AppleDouble
141
+ .LSOverride
142
+
143
+ # Thumbnails
144
+ ._*
145
+ .Spotlight-V100
146
+ .Trashes
147
+ ehthumbs.db
148
+ Thumbs.db
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGP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I
18
+ rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
19
+ HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
20
+ hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
21
+ ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
22
+ 3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
23
+ NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
24
+ ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
25
+ TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
26
+ jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
27
+ oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
28
+ 4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
29
+ mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
30
+ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
README.md CHANGED
@@ -1,12 +1,16 @@
1
  ---
2
- title: Huggingface Mcp
3
- emoji: 🐨
4
- colorFrom: red
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.33.0
8
  app_file: app.py
9
  pinned: false
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: huggingface-mcp
3
+ emoji: 💻
4
+ colorFrom: indigo
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 5.33.0
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
+ short_description: some huggingface api as a mcp
12
+ tags:
13
+ - mcp-server-track
14
  ---
15
 
16
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from huggingface_hub import list_spaces, whoami, HfFolder
4
+ from huggingface_hub.hf_api import HfHubHTTPError
5
+
6
+ def list_my_hf_spaces(hf_username_or_org: str):
7
+ """
8
+ Lists all Hugging Face Spaces for a given username or organization.
9
+
10
+ Args:
11
+ hf_username_or_org (str): The Hugging Face username or organization name.
12
+
13
+ Returns:
14
+ list: A list of dictionaries, where each dictionary contains details of a space.
15
+ Suitable for use with gradio.DataFrame. Returns a list with an error
16
+ message if an issue occurs.
17
+ """
18
+ try:
19
+ print(f"Fetching Hugging Face Spaces for user/org: {hf_username_or_org}") # Server-side log
20
+ if not hf_username_or_org or not hf_username_or_org.strip():
21
+ # Return list of lists format for error
22
+ return [["Error", "Username/Organization cannot be empty.", "-", "-", "-", "-"]]
23
+
24
+ spaces_objects = list_spaces(author=hf_username_or_org.strip())
25
+
26
+ if not spaces_objects:
27
+ # Return list of lists format for no spaces found
28
+ return [[f"No spaces found for '{hf_username_or_org}'", "Check username/org or authentication.", "-", "-", "-", "-"]]
29
+
30
+ spaces_data_list_of_lists = []
31
+ for space in spaces_objects:
32
+ row = [
33
+ f"[{space.id}](https://huggingface.co/spaces/{space.id})",
34
+ getattr(space, 'author', 'N/A'),
35
+ str(getattr(space, 'lastModified', 'N/A')),
36
+ str(getattr(space, 'private', 'N/A')),
37
+ str(getattr(space, 'gated', 'N/A')),
38
+ getattr(space, 'sdk', 'N/A')
39
+ ]
40
+ spaces_data_list_of_lists.append(row)
41
+
42
+ return spaces_data_list_of_lists
43
+
44
+ except Exception as e:
45
+ error_message = f"An error occurred: {str(e)}. Ensure correct username/org and HF authentication (huggingface-cli login or HF_TOKEN)."
46
+ print(error_message) # Server-side log
47
+ # Return list of lists format for exception
48
+ return [["Error", error_message, "-", "-", "-", "-"]]
49
+
50
+
51
+ def list_my_hf_organizations(token: str = None):
52
+ """
53
+ Lists organizations the Hugging Face user (identified by the token) is a member of.
54
+
55
+ Args:
56
+ token (str, optional): Hugging Face API token.
57
+ If None or empty, attempts to load token via HfFolder.get_token().
58
+
59
+ Returns:
60
+ list: A list of lists, where each inner list contains an organization name (as a Markdown link).
61
+ Suitable for use with gradio.DataFrame.
62
+ """
63
+ try:
64
+ if not token: # If token param is None or empty
65
+ token = HfFolder.get_token()
66
+ if not token:
67
+ return [["Error: Not logged in", "Please log in using 'huggingface-cli login'."]]
68
+
69
+ print("Fetching organizations for the authenticated user...") # Server-side log
70
+ user_info = whoami(token=token)
71
+
72
+ if not user_info or 'orgs' not in user_info:
73
+ return [["Info", "No organization information found or user data incomplete."]]
74
+
75
+ org_list_from_api = user_info.get('orgs', [])
76
+ if not org_list_from_api:
77
+ return [["Info", "Authenticated user is not a member of any organizations."]]
78
+
79
+ orgs_data = []
80
+ for org_dict in org_list_from_api:
81
+ org_name = org_dict.get('name')
82
+ if org_name:
83
+ org_link = f"[{org_name}](https://huggingface.co/{org_name})"
84
+ orgs_data.append([org_link]) # Store as a list containing the Markdown link
85
+
86
+ if not orgs_data:
87
+ return [["Info", "Found organization entries but no names extracted."]]
88
+ return orgs_data
89
+
90
+ except HfHubHTTPError as e:
91
+ if e.response.status_code == 401:
92
+ error_msg = "Authentication error. Please ensure you are logged in ('huggingface-cli login')."
93
+ else:
94
+ error_msg = f"API Error: {str(e)}"
95
+ print(error_msg) # Server-side log
96
+ return [["Error", error_msg]]
97
+ except Exception as e:
98
+ error_message = f"An unexpected error occurred: {str(e)}"
99
+ print(error_message) # Server-side log
100
+ return [["Error", error_message]]
101
+
102
+
103
+ def list_organization_spaces(org_name: str):
104
+ """
105
+ Lists all public Hugging Face Spaces for a given organization.
106
+
107
+ Args:
108
+ org_name (str): The name of the Hugging Face organization.
109
+
110
+ Returns:
111
+ list: A list of lists, where each inner list contains Space details.
112
+ Suitable for use with gradio.DataFrame.
113
+ The Space ID is formatted as a Markdown link.
114
+ """
115
+ try:
116
+ if not org_name or not org_name.strip():
117
+ return [["Error", "Organization name cannot be empty.", "-", "-", "-", "-"]]
118
+
119
+ print(f"Fetching Hugging Face Spaces for organization: {org_name.strip()}") # Server-side log
120
+ spaces_objects = list_spaces(author=org_name.strip()) # Use author field for organization
121
+
122
+ if not spaces_objects:
123
+ return [[f"No Spaces found for organization '{org_name.strip()}'", "Organization may not exist or have no public spaces.", "-", "-", "-", "-"]]
124
+
125
+ spaces_data_list_of_lists = []
126
+ for space in spaces_objects:
127
+ row = [
128
+ f"[{space.id}](https://huggingface.co/spaces/{space.id})",
129
+ getattr(space, 'author', 'N/A'),
130
+ str(getattr(space, 'lastModified', 'N/A')),
131
+ str(getattr(space, 'private', 'N/A')),
132
+ str(getattr(space, 'gated', 'N/A')),
133
+ getattr(space, 'sdk', 'N/A')
134
+ ]
135
+ spaces_data_list_of_lists.append(row)
136
+
137
+ return spaces_data_list_of_lists
138
+
139
+ except HfHubHTTPError as e:
140
+ error_msg = f"API Error for organization '{org_name.strip()}': {str(e)}"
141
+ print(error_msg) # Server-side log
142
+ return [["Error", error_msg, "-", "-", "-", "-"]]
143
+ except Exception as e:
144
+ error_message = f"An unexpected error occurred for organization '{org_name.strip()}': {str(e)}"
145
+ print(error_message) # Server-side log
146
+ return [["Error", error_message, "-", "-", "-", "-"]]
147
+
148
+
149
+ # Gradio interface for listing Hugging Face Spaces
150
+ hf_spaces_interface = gr.Interface(
151
+ fn=list_my_hf_spaces,
152
+ inputs=[gr.Textbox(label="Hugging Face Username or Organization", placeholder="e.g., huggingface, stabilityai, or your_username")],
153
+ outputs=[gr.DataFrame(
154
+ headers=["ID", "Author", "Last Modified", "Private", "Gated", "SDK"],
155
+ label="Hugging Face Spaces",
156
+ wrap=True, # Allow text wrapping in cells
157
+ datatype=["markdown", "str", "str", "str", "str", "str"] # Render first column as Markdown
158
+ )],
159
+ title="Hugging Face api as mcp",
160
+ description="Enter a Hugging Face username or organization to list their public Spaces.",
161
+ examples=[["huggingface"], ["stabilityai"], ["gradio"]],
162
+ allow_flagging='never'
163
+ )
164
+
165
+ hf_orgs_interface = gr.Interface(
166
+ fn=list_my_hf_organizations,
167
+ inputs=[gr.Textbox(label="Hugging Face Token (Optional)", placeholder="hf_xxx... or leave blank to use logged-in user", type="password")],
168
+ outputs=[gr.DataFrame(
169
+ headers=["My Organization Name"],
170
+ label="My Hugging Face Organizations",
171
+ wrap=True,
172
+ datatype=["markdown"] # Render column as Markdown
173
+ )],
174
+ title="My Hugging Face Organizations Lister",
175
+ description="Lists the Hugging Face organizations you are a member of. Requires you to be logged in via 'huggingface-cli login'. Get your token from [here](https://huggingface.co/settings/tokens). Click 'Submit' to refresh.",
176
+ allow_flagging='never'
177
+ )
178
+
179
+
180
+ hf_org_spaces_interface = gr.Interface(
181
+ fn=list_organization_spaces,
182
+ inputs=[gr.Textbox(label="Organization Name", placeholder="e.g., huggingface, stabilityai")],
183
+ outputs=[gr.DataFrame(
184
+ headers=["ID", "Author", "Last Modified", "Private", "Gated", "SDK"],
185
+ label="Organization's Hugging Face Spaces",
186
+ wrap=True,
187
+ datatype=["markdown", "str", "str", "str", "str", "str"]
188
+ )],
189
+ title="List Organization's Spaces",
190
+ description="Enter a public Hugging Face organization name to list their Spaces.",
191
+ examples=[["huggingface"], ["stabilityai"], ["google"]],
192
+ allow_flagging='never'
193
+ )
194
+
195
+ if __name__ == "__main__":
196
+ tabbed_demo = gr.TabbedInterface(
197
+ [hf_spaces_interface, hf_orgs_interface, hf_org_spaces_interface],
198
+ ["List Spaces by User/Org", "List My Organizations", "List Org Spaces"]
199
+ )
200
+ tabbed_demo.launch(mcp_server=True, share=True)
requirements.txt ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==24.1.0
2
+ annotated-types==0.7.0
3
+ anyio==4.9.0
4
+ certifi==2025.4.26
5
+ charset-normalizer==3.4.2
6
+ click==8.2.1
7
+ fastapi==0.115.12
8
+ ffmpy==0.6.0
9
+ filelock==3.18.0
10
+ fsspec==2025.5.1
11
+ gradio==5.33.0
12
+ gradio_client==1.10.2
13
+ groovy==0.1.2
14
+ h11==0.16.0
15
+ hf-xet==1.1.3
16
+ httpcore==1.0.9
17
+ httpx==0.28.1
18
+ httpx-sse==0.4.0
19
+ huggingface-hub==0.32.4
20
+ idna==3.10
21
+ Jinja2==3.1.6
22
+ markdown-it-py==3.0.0
23
+ MarkupSafe==3.0.2
24
+ mcp==1.9.0
25
+ mdurl==0.1.2
26
+ numpy==2.2.6
27
+ orjson==3.10.18
28
+ packaging==25.0
29
+ pandas==2.2.3
30
+ pillow==11.2.1
31
+ pydantic==2.11.5
32
+ pydantic-settings==2.9.1
33
+ pydantic_core==2.33.2
34
+ pydub==0.25.1
35
+ Pygments==2.19.1
36
+ python-dateutil==2.9.0.post0
37
+ python-dotenv==1.1.0
38
+ python-multipart==0.0.20
39
+ pytz==2025.2
40
+ PyYAML==6.0.2
41
+ requests==2.32.3
42
+ rich==14.0.0
43
+ ruff==0.11.12
44
+ safehttpx==0.1.6
45
+ semantic-version==2.10.0
46
+ shellingham==1.5.4
47
+ six==1.17.0
48
+ sniffio==1.3.1
49
+ sse-starlette==2.3.6
50
+ starlette==0.46.2
51
+ tomlkit==0.13.2
52
+ tqdm==4.67.1
53
+ typer==0.16.0
54
+ typing-inspection==0.4.1
55
+ typing_extensions==4.14.0
56
+ tzdata==2025.2
57
+ urllib3==2.4.0
58
+ uvicorn==0.34.3
59
+ websockets==15.0.1