Download app.py from 13ze/wp-cli: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/13ze/wp-cli/resolve/main/app.py
- Command line
-
hf download hf://spaces/13ze/wp-cli/app.py
-
curl -L -o app.py https://huggingface.co/spaces/13ze/wp-cli/resolve/main/app.py
1.85 kB
| import gradio as gr | |
| import requests | |
| import os | |
| from requests.auth import HTTPBasicAuth | |
| def test_wp_rest_api(endpoint): | |
| """ | |
| Função para testar endpoints básicos da API REST do WordPress. | |
| """ | |
| try: | |
| # Recupera as variáveis de ambiente seguras | |
| wp_app_password = os.getenv("WP_APP_PASSWORD") | |
| wp_user = os.getenv("WP_USER") | |
| wp_url = os.getenv("WP_URL") | |
| # Verifica se as variáveis estão definidas | |
| if not wp_app_password: | |
| return "Erro: Variável de ambiente WP_APP_PASSWORD não definida." | |
| if not wp_user: | |
| return "Erro: Variável de ambiente WP_USER não definida." | |
| if not wp_url: | |
| return "Erro: Variável de ambiente WP_URL não definida." | |
| # URL do endpoint da API REST | |
| api_url = f"{wp_url}/wp-json/wp/v2/{endpoint}" | |
| # Configura a autenticação | |
| auth = HTTPBasicAuth(wp_user, wp_app_password) | |
| # Executa a requisição GET no endpoint da API REST | |
| response = requests.get(api_url, auth=auth) | |
| if response.status_code != 200: | |
| return f"Erro ao acessar o endpoint: {response.text}" | |
| return response.json() | |
| except Exception as e: | |
| return f"Erro: {str(e)}" | |
| # Lista de endpoints básicos da API REST | |
| endpoints = [ | |
| "posts", | |
| "users", | |
| "categories" | |
| ] | |
| # Cria a interface Gradio | |
| iface = gr.Interface( | |
| fn=test_wp_rest_api, # Função que será chamada | |
| inputs=[ | |
| gr.Dropdown(choices=endpoints, label="Endpoint da API REST") # Menu suspenso para selecionar o endpoint | |
| ], | |
| outputs="text", # Saída de texto com o resultado | |
| title="Testador de API REST do WordPress", # Título do painel | |
| description="Selecione um endpoint da API REST para testar." # Descrição do painel | |
| ) | |
| # Inicia a interface | |
| iface.launch() | |