Spaces:
Runtime error
Runtime error
import gradio as gr | |
import subprocess | |
import json | |
def api_call(input_text): | |
# Replace 'YOUR_CURL_COMMAND' with the actual cURL command you want to use | |
curl_command = [ | |
'curl', '-s', '--request', 'GET', | |
'--url', f"https://api.padlet.dev/v1/boards/{input_text}?include=posts%2Csections", | |
'--header', 'X-Api-Key: pdltp_0e380a0de1ff32d77b12dbcc030b1373199b7525681ddc81bd1b9ef3e4e3dd49577a23', | |
'--header', 'accept: application/vnd.api+json' | |
] | |
try: | |
response = subprocess.check_output(curl_command, universal_newlines=True) | |
response_data = json.loads(response) | |
# Extract the contents of all posts | |
posts_data = response_data.get("included", []) | |
post_contents = [] | |
for post in posts_data: | |
if post.get("type") == "post": | |
content = post.get("attributes", {}).get("content", {}).get("subject", "") | |
if content: | |
post_contents.append(content) | |
return "\n".join(post_contents) if post_contents else "No post contents found." | |
except subprocess.CalledProcessError: | |
return "Error: Unable to fetch data using cURL." | |
iface = gr.Interface( | |
fn=api_call, | |
inputs=gr.inputs.Textbox(), | |
outputs=gr.outputs.Textbox(), | |
live=True, | |
title="Padlet API Caller with cURL", | |
description="Enter Padlet board ID and get board details using cURL" | |
) | |
iface.launch() |